Monday, June 11, 2012

Query to get the list of partitioned tables

If COUNT(*) = 1, then there are no partitions (only one partition, that is the table)

If COUNT(*) > 1, then there are multiple partitions


SELECT s.name AS SchemaName, t.name AS TableName



FROM SYS.TABLES t


INNER JOIN SYS.SCHEMAS s On t.schema_id = s.schema_id


INNER JOIN SYS.PARTITIONS p on p.object_id = t.object_id


WHERE p.index_id IN (0, 1)


GROUP BY s.name, t.name


HAVING COUNT(*) > 1


ORDER BY s.name, t.name;



No comments: