views:

48

answers:

3

A view created, certain users have direct access to the database using the same web application. If the base table is changed (data) will the view automatically reflect the changes/insert in data, or will it need to be created again and again? Vs08 sql-server-2005 c#  

+1  A: 

Views recalculate themselves automatically. When this happens depends on the specific engine in use (read: I have no clue when for SQL Server 2005).

Ignacio Vazquez-Abrams
+3  A: 

Views are like windows, they just let you see what's in the table. They don't contain a copy of the table or anything like that.

If you change the definition of the table, like add or remove a column, you should rebuild the view. But if you are just doing insert/update/delete, then everything will just work.

Jonathan Allen
"But if you are just doing insert/update/delete, then everything will just work." i am doing it to the base table not the view, even then 'every thing will be fine?'
@user287745: yes.
Michael Petrotta
Indexed views in SQL Server or materialized views in other RDBMS do in fact store a copy of the data - but even that copy is always kept up to date.
marc_s
+1  A: 

In effect, a view is a just a pre-written select statement.

Every time you make a call to the database for a particular view, the select statement runs and the current dataset in the base table(s) is returned.

You won't see live changes in an application front-end if someone else makes a change to the data table but you will see any changes as soon as you make a new request for the view.

melkisadek
This is not entirely true for indexed views in SQL Server - they actually do store the data contained in the result of the view on disk. They're not really just a pre-written select statement...
marc_s
"In effect" was shorthand for "here be dragons..." :DIn the context of the question an indexed view would not reflect any changes to other users until it was run again. As this needs to be done for a normal view anyway, the differentiation is probably unnecessary.However, +1 for clarity and further explanation - something that gets forgotten about when answering a specific question.
melkisadek
thank you, but unfortunately only one can be marked as answer :-)