snippetsqlMinor
How to create a view that refresh automatically
Viewed 0 times
createautomaticallyrefreshviewthathow
Problem
I was triying to create a View by the simplest way like this:
How can I do, so that view keeps its link to the table so if a change the table the view also changes, without creating it again or creating a new one. Is that possible? Im working with Sql Server 2008 R2 thanxs
Use SoccerDB;
GO
CREATE VIEW ExampleDBaseII
AS
SELECT ID, Cast(Name AS Varchar) as Name,Cast(City AS Varchar) as City,
FROM Team
GOHow can I do, so that view keeps its link to the table so if a change the table the view also changes, without creating it again or creating a new one. Is that possible? Im working with Sql Server 2008 R2 thanxs
Solution
Use
This will disallow any changes to the underling tables that could affect the view
It also requires the use of qualifiers (schema, alias) and disallows the use of
Which is a good thing (SO link)
WITH SCHEMABINDING in the viewCREATE VIEW ExampleDBaseII
WITH SCHEMABINDING
AS
SELECT T.ID, Cast(T.Name AS Varchar) as Name, Cast(T.City AS Varchar) as City,
FROM Team T
GOThis will disallow any changes to the underling tables that could affect the view
It also requires the use of qualifiers (schema, alias) and disallows the use of
SELECT *. Which is a good thing (SO link)
Code Snippets
CREATE VIEW ExampleDBaseII
WITH SCHEMABINDING
AS
SELECT T.ID, Cast(T.Name AS Varchar) as Name, Cast(T.City AS Varchar) as City,
FROM Team T
GOContext
StackExchange Database Administrators Q#6834, answer score: 9
Revisions (0)
No revisions yet.