Wednesday, December 8, 2010

Find Table without Clustered Index / Primary Key

One of the basic Database Rule I have is that all the table must Clustered Index. Clustered Index speeds up performance of the query ran on that table. Clustered Index are usually Primary Key but not necessarily.

SELECT OBJECT_NAME(i.OBJECT_ID) AS tableName, rows
FROM sys.indexes i
INNER JOIN sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
WHERE i.INDEX_ID = 0
AND OBJECTPROPERTY(i.OBJECT_ID,'IsUserTable') = 1
ORDER BY 2 DESC 
 

0 comments:

Post a Comment