I got into a bit of a situation today. There were some performance issues in our performance testing environment and my changes (and a few others) were finally being tested. I was also told by various levels of management not to work on this project – concentrate my efforts on Project B. All I could think was my changes had to be using the correct indexes – how could I tell with out a lot of work – DMVs on index usage stats. I fired up google and found this from mssqltips.com. I changed the select a little and added the fairly accurate way to get row counts as a CTE. Here’s what I came up with:
;With RowCounts_CTE as (SELECT so.id, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name) GROUP BY so.id, so.name) SELECT OBJECT_NAME(S.[OBJECT_ID]) AS [OBJECT NAME], I.[NAME] AS [INDEX NAME], RC.[RowCount], USER_SEEKS, USER_SCANS, USER_LOOKUPS, USER_UPDATES FROM SYS.DM_DB_INDEX_USAGE_STATS AS S INNER JOIN SYS.INDEXES AS I ON I.[OBJECT_ID] = S.[OBJECT_ID] AND I.INDEX_ID = S.INDEX_ID Join RowCounts_CTE RC on RC.id = S.object_id WHERE OBJECTPROPERTY(S.[OBJECT_ID],'IsUserTable') = 1 Order by 1



