Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 will a query within a view always executes??

Author  Topic 

harishprasadp
Starting Member

2 Posts

Posted - 2010-03-16 : 14:36:16
Hi,

When we create a view and then later at some point of time we call that view, will the select query within the view be executed every time or it stores the data when it is executed for the first time and then from the second time onwards it gives the result form cache [or some form of saving the result set]?

My 2nd question is

if the view returns from the cache, how does the changes in the tables reflect in the view? How come the view gets to know whether the tables has been modified or not??

I am referring to MS SQL Server 2005.



Thanks and Regards,
Harish Prasdad Popuri

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-16 : 14:43:01
It most likely will come from cache, just depends on how much memory you have and what else wants to be stored in cache. SQL Server will manage moving data pages in and out of cache for you. It keeps track of everything.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-17 : 05:33:45
" will the select query within the view be executed every time or it stores the data when it is executed for the first time"

The VIEW is executed every time, there is no data "stored" for the VIEW.

This is slightly blurred if you have an INDEX on the View ... but SQL takes care of that, behind the scenes, as Tara said - so you don't have to "Refresh" the view, or anything like that.
Go to Top of Page

harishprasadp
Starting Member

2 Posts

Posted - 2010-03-17 : 05:59:58
Thank you Kristen and Tara ..

Thanks and Regards,
Harish Prasdad Popuri
Go to Top of Page
   

- Advertisement -