|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:43 AM
Points: 38,106,
Visits: 30,397
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, February 01, 2013 9:13 AM
Points: 1,
Visits: 52
|
|
This works for SQL 2005 and above but I'm having problems with SQL 2000; can anyone rewrite for SQL 2000?
Is there and equivalent for sys.dm_db_index_usage_stats etc in SQL 2000?
Thanks in advance
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, May 23, 2013 1:42 PM
Points: 3,
Visits: 9
|
|
Is there to find unused functions and procedures as well? Or time since last call to these objects?
Thanks
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:43 AM
Points: 38,106,
Visits: 30,397
|
|
Chris Holding (11/4/2010) This works for SQL 2005 and above but I'm having problems with SQL 2000; can anyone rewrite for SQL 2000?
No, because the information is not there in SQL 2000. If you want this kind of info in SQL 2000, you'll need a trace (SQL Trace)
Is there and equivalent for sys.dm_db_index_usage_stats etc in SQL 2000? No
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, August 30, 2011 1:26 PM
Points: 362,
Visits: 59
|
|
So I added a bit to it and made it so it will run aginst every database on the server. Hope this helps someone.
CREATE TABLE #LastAccess (DatabaseName sysname, TableName sysname, LastSelect datetime) DECLARE @SQL varchar(max) SET @SQL = 'USE ?; ' + 'WITH LastActivity (ObjectID, LastAction) AS ' + '( ' + 'SELECT object_id, ' + 'last_user_seek as LastAction ' + 'FROM sys.dm_db_index_usage_stats ' + 'WHERE database_id = db_id(db_name()) ' + 'UNION SELECT object_id, ' + 'last_user_scan as LastAction ' + 'FROM sys.dm_db_index_usage_stats ' + 'WHERE database_id = db_id(db_name()) ' + 'UNION SELECT object_id, ' + 'last_user_lookup as LastAction ' + 'FROM sys.dm_db_index_usage_stats ' + 'WHERE database_id = db_id(db_name()) ' + ') ' + 'INSERT INTO #LastAccess ' + 'SELECT DB_NAME() AS DatabaseName, ' + 'OBJECT_NAME(so.object_id) AS TableName, ' + 'MAX(la.LastAction) as LastSelect ' + 'FROM sys.objects so ' + 'LEFT JOIN LastActivity la ' + 'ON so.object_id = la.ObjectID ' + 'WHERE so.type = ''U'' ' + 'AND so.object_id > 100 ' + 'GROUP BY OBJECT_NAME(so.object_id) ' + 'ORDER BY OBJECT_NAME(so.object_id) '
EXEC sp_MSforeachdb @SQL
SELECT * FROM #LastAccess
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, November 19, 2012 11:28 PM
Points: 8,
Visits: 19
|
|
| Many thanks for such useful script !!!!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, February 27, 2012 10:47 AM
Points: 1,
Visits: 16
|
|
Very helpful. Thanks for the script
|
|
|
|
|
SSC-Insane
         
Group: General Forum Members
Last Login: Yesterday @ 8:44 PM
Points: 21,376,
Visits: 9,585
|
|
| You need to wrap the first ? with [?] so that non-standard db names don't fail.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, August 30, 2011 1:26 PM
Points: 362,
Visits: 59
|
|
|
|
|