|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to tell if an Index has ever been used...Hi,
Is there a way to tell if an index has EVER been used on a table (apart from going back in time and setting up a trace for it)? Thanks. Rob wrote:
> Hi, Which version of SQL?> > Is there a way to tell if an index has EVER been used on a table (apart from > going back in time and setting up a trace for it)? > > Thanks. Sorry, for SQL 2000
Show quote "Tracy McKibben" wrote: > Rob wrote: > > Hi, > > > > Is there a way to tell if an index has EVER been used on a table (apart from > > going back in time and setting up a trace for it)? > > > > Thanks. > > Which version of SQL? > > > -- > Tracy McKibben > MCDBA > http://www.realsqlguy.com > Rob wrote:
> Sorry, for SQL 2000 Unfortunately, Profiler is your only true option... Sounds like you > already knew that though... http://www.sql-server-performance.com/lm_index_elimination_english.asp Depends on what version of SQL Server you are using.
In SQL Server 2005, you can get index usage stats from here: SELECT TableName = OBJECT_NAME(s.[object_id]), IndexName = i.name, s.last_user_seek, s.last_user_scan, s.last_user_lookup, s.last_user_update, s.last_system_seek, s.last_system_scan, s.last_system_lookup, s.last_system_update FROM sys.dm_db_index_usage_stats s INNER JOIN sys.indexes i ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id WHERE s.database_id = DB_ID() AND OBJECTPROPERTY(s.[object_id], 'IsMsShipped') = 0; Of course if you are interested in a specific table, or table + index, you could add to the where clause accordingly. A Show quote "Rob" <R**@discussions.microsoft.com> wrote in message news:CD88E3F9-C22A-4B3C-B45A-7BB44DC772F0@microsoft.com... > Hi, > > Is there a way to tell if an index has EVER been used on a table (apart > from > going back in time and setting up a trace for it)? > > Thanks. Rob
All indexes which haven’t been used yet can be retrieved with the following statement: select object_name(object_id), i.name from sys.indexes i where i.index_id NOT IN (select s.index_id from sys.dm_db_index_usage_stats s where s.object_id=i.object_id and i.index_id=s.index_id and database_id = <dbid> ) order by object_name(object_id) asc Show quote "Rob" <R**@discussions.microsoft.com> wrote in message news:CD88E3F9-C22A-4B3C-B45A-7BB44DC772F0@microsoft.com... > Hi, > > Is there a way to tell if an index has EVER been used on a table (apart > from > going back in time and setting up a trace for it)? > > Thanks. .... and remember that this is since last restart of the database engine.
-- Show quoteTibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www.solidqualitylearning.com/ "Uri Dimant" <u***@iscar.co.il> wrote in message news:u1QMzkk1GHA.3476@TK2MSFTNGP04.phx.gbl... > Rob > All indexes which haven't been used yet can be retrieved with the following statement: > > select object_name(object_id), i.name > from sys.indexes i > where i.index_id NOT IN (select s.index_id > from sys.dm_db_index_usage_stats s > where s.object_id=i.object_id and > i.index_id=s.index_id and > database_id = <dbid> ) > order by object_name(object_id) asc > > > > "Rob" <R**@discussions.microsoft.com> wrote in message > news:CD88E3F9-C22A-4B3C-B45A-7BB44DC772F0@microsoft.com... >> Hi, >> >> Is there a way to tell if an index has EVER been used on a table (apart from >> going back in time and setting up a trace for it)? >> >> Thanks. > > |
|||||||||||||||||||||||