|
View Linkadas com as Tabelas
|
Blogger |
O que você gostaria de ver nesta página? Envie sua sugestão.
View Linkadas com as TabelasComo criar VIEW associando a mesma as alterações das tabelas, ou seja, associando ao esquema do bancoCREATE VIEW Uma opção importante na criação de uma view é a opção "WITH SCHEMABINDING", que liga a view ao esquema das tabelas básicas, protegendo na estrutura da tabela e invalidadndo sua view. É importante lembrar que os nomes das tabelas devem ser precedidas do proprietário (Ex: dbo.table). Caso contrário, apresentará o seguinte erro: Server: Msg 4512, Level 16, State 3, Procedure view_teste, Line 4 Cannot schema bind view 'dbo.view_teste' because name 'sysobjects' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself. Exemplo da criação de uma view com SCHEMABINDING: CREATE TABLE dbo.teste ( [t1] int ,[t2] int ) CREATE VIEW dbo.view_teste WITH SCHEMABINDING AS SELECT [t2] FROM dbo.teste Exemplo de uma tentativa de remover uma coluna que está em uma view: ALTER TABLE dbo.teste DROP COLUMN [t2] go Server: Msg 5074, Level 16, State 3, Line 1 The object 'view_teste' is dependent on column 't2'. Server: Msg 4922, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN t2 failed because one or more objects access this column. Outra tentativa, agora tentando remover a tabela: DROP VIEW dbo.view_teste go Server: Msg 3729, Level 16, State 1, Line 1 Cannot DROP TABLE 'dbo.teste' because it is being referenced by object 'view_teste'. Para apagar a tabela basta remover primeiro a view, depois a tabela: DROP VIEW dbo.view_teste go DROP TABLE dbo.teste go |
importar no delicious Domínio Grátis! Hospedagem de Páginas Grátis Backup Online Grátis HK-450 Metal Upgrade Belt CP V2 EK1H-E014D BELT CP KIT Blogs: Poker RegrasPokercores htmlwebdesign poker de graça importar no delicious Bookmark to:
Aeromodelismo Helicopter |