Monitoring views


There's a way to know when a view is accessed and which query is executed in SQL Server 2005/2008?

Thanks for any help.

P.S. Sorry for my english.

more ▼

asked Nov 09, 2009 at 10:50 AM in Default

user-516 gravatar image

1 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

The best way to monitor what is being used to either set up a custom server-side trace to capture queries as they occur. You can also look at the default trace that's running on the server, but that's only going to have recent data available. Another option is to query the dynamic management function sys.dm_exec_sql_text. That will show you what's been running and is still in cache.

Of the options, a custom server-side trace will give you the most direct control and flexibility. My second choice would be the DMV's.

more ▼

answered Nov 09, 2009 at 11:25 AM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
103k 19 21 74

Grant is completely right, but be aware that the performance price of a server side trace can be quite high (depending of course on how close to maximum capacity the server is).

One other option you may want to look at is giving them access to the view only through stored procedures. The stored procedure can then log its use as part of its execution. This brings with its own complications of course, but it could be a good trade off depending on your circumstances.
Nov 09, 2009 at 01:58 PM TimothyAWiseman
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Nov 09, 2009 at 10:50 AM

Seen: 835 times

Last Updated: Nov 09, 2009 at 11:58 AM