Tuesday, February 2, 2016

Tables that do not have a clustered index

--How to find all the tables that do not have a clustered index in a specified database

SELECT SCHEMA_NAME(t.schema_id) AS schema_name, t.name AS table_name
FROM sys.tables AS t
WHERE NOT EXISTS
   (
     SELECT * FROM sys.indexes AS i
     WHERE i.object_id = t.object_id
     AND i.type = 1  -- or type_desc = 'CLUSTERED'
   )
ORDER BY schema_name, table_name;


GO

No comments:

Post a Comment