dbTalk Databases Forums  

removing unused objects - SQL Server 2000 or 2005

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss removing unused objects - SQL Server 2000 or 2005 in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kellygreer1
 
Posts: n/a

Default removing unused objects - SQL Server 2000 or 2005 - 01-21-2008 , 06:36 PM






Sometimes at the end of a project you'll end up with unused Tables,
Stored Procs, Functions, and Views.
Since there is not something like a 'SELECT' trigger ... what is the
best way for telling what is not being used by your solution? To turn
on some kind of tracing?

Any ideas?

Thanks,
Kelly Greer
kellygreer1 (AT) nospam (DOT) com
change nospam to yahoo


Reply With Quote
  #2  
Old   
Uri Dimant
 
Posts: n/a

Default Re: removing unused objects - SQL Server 2000 or 2005 - 01-22-2008 , 02:35 AM






Copy -Paste from Tony articles

In SQL 2005 there is, sort of. This is query lists the last execution
time for all SQL modules in a database:

SELECT object_name(m.object_id), MAX(qs.last_execution_time)
FROM sys.sql_modules m
LEFT JOIN (sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st)
ON m.object_id = st.objectid
AND st.dbid = db_id()
GROUP BY object_name(m.object_id)

But there are tons of caveats. The starting point of this query is
the dynamic management view dm_exec_query_stats, and the contents is
per *query plan*. If a stored procedure contains several queries,
there are more than one entry for the procedure in dm_exec_query_stats.



"kellygreer1" <kellygreer1 (AT) yahoo (DOT) com> wrote

Quote:
Sometimes at the end of a project you'll end up with unused Tables,
Stored Procs, Functions, and Views.
Since there is not something like a 'SELECT' trigger ... what is the
best way for telling what is not being used by your solution? To turn
on some kind of tracing?

Any ideas?

Thanks,
Kelly Greer
kellygreer1 (AT) nospam (DOT) com
change nospam to yahoo




Reply With Quote
  #3  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: removing unused objects - SQL Server 2000 or 2005 - 01-22-2008 , 04:15 PM



Uri Dimant (urid (AT) iscar (DOT) co.il) writes:
Quote:
Copy -Paste from Tony articles

In SQL 2005 there is, sort of. This is query lists the last execution
time for all SQL modules in a database:

SELECT object_name(m.object_id), MAX(qs.last_execution_time)
FROM sys.sql_modules m
LEFT JOIN (sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st)
ON m.object_id = st.objectid
AND st.dbid = db_id()
GROUP BY object_name(m.object_id)

But there are tons of caveats. The starting point of this query is
the dynamic management view dm_exec_query_stats, and the contents is
per *query plan*. If a stored procedure contains several queries,
there are more than one entry for the procedure in dm_exec_query_stats.
And very importantly: it only lists what's in the cache. A procedure could
fall out of the cahce for several reasons. For instance, adding an index
on a table, flushes all plans related to that table. And a server restart
empites the cache entirely.

I would be very careful to use information of that kind to draw
conclusion of whether an object is in use.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #4  
Old   
Alex Kuznetsov
 
Posts: n/a

Default Re: removing unused objects - SQL Server 2000 or 2005 - 01-22-2008 , 04:28 PM



On Jan 21, 6:36 pm, kellygreer1 <kellygre... (AT) yahoo (DOT) com> wrote:
Quote:
Sometimes at the end of a project you'll end up with unused Tables,
Stored Procs, Functions, and Views.
Since there is not something like a 'SELECT' trigger ... what is the
best way for telling what is not being used by your solution? To turn
on some kind of tracing?

Any ideas?

Thanks,
Kelly Greer
kellygre... (AT) nospam (DOT) com
change nospam to yahoo
have you checked out SQL Dependency Tracker?


Reply With Quote
  #5  
Old   
kellygreer1
 
Posts: n/a

Default Re: removing unused objects - SQL Server 2000 or 2005 - 01-22-2008 , 06:00 PM



On Jan 22, 5:28 pm, Alex Kuznetsov <alk... (AT) gmail (DOT) com> wrote:
Quote:
On Jan 21, 6:36 pm,kellygreer1<kellygre... (AT) yahoo (DOT) com> wrote:

Sometimes at the end of a project you'll end up with unused Tables,
Stored Procs, Functions, and Views.
Since there is not something like a 'SELECT' trigger ... what is the
best way for telling what is not being used by your solution? To turn
on some kind of tracing?

Any ideas?

Thanks,
Kelly Greer
kellygre... (AT) nospam (DOT) com
change nospam to yahoo

have you checked out SQL Dependency Tracker?
Thanks for the ideas. I'm going to try this SQL Dependency Tracker
too.
See they have a trial on their site.

kellygreer1


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.