/ Published in: SQL
SQL Server - everything you want to know (or not) about a table.
Expand |
Embed | Plain Text
SELECT top 10 @@ServerName AS ServerName, db_name() AS [DATABASE], object_schema_name(t.object_id) AS [schema], --object_name(t.object_id) as [name], (SELECT count(1) FROM sys.COLUMNS AS c WHERE c.object_id = t.object_id) AS [COLUMNS], (SELECT name FROM sys.database_principals WHERE principal_id = isnull(t.principal_id,(SELECT principal_id FROM sys.schemas AS s WHERE s.schema_id = t.schema_id)) ) AS [owner], t.*, s.* FROM sys.TABLES AS t JOIN (SELECT object_id, --count(partition_id) count(DISTINCT index_id) AS indexes, max(case when index_id = 0 then 'Heap' when index_id = 1 then 'Clustered' else '' end) AS HOBT, max(partition_number) AS partitions, sum(in_row_data_page_count)*8192 AS in_row_data_page_bytes, sum(in_row_used_page_count)*8192 AS in_row_used_page_bytes, sum(in_row_reserved_page_count)*8192 AS in_row_reserved_page_bytes, sum(lob_used_page_count)*8192 AS lob_used_page_bytes, sum(lob_reserved_page_count)*8192 AS lob_reserved_page_bytes, sum(row_overflow_used_page_count)*8192 AS row_overflow_used_page_bytes, sum(row_overflow_reserved_page_count)*8192 AS row_overflow_reserved_page_bytes, sum(used_page_count)*8192 AS used_page_bytes, sum(reserved_page_count)*8192 AS reserved_page_bytes, sum(case when index_id < 2 then row_count else 0 end) AS rows FROM sys.dm_db_partition_stats AS x GROUP BY object_id ) AS s ON s.object_id = t.object_id ORDER BY used_page_bytes DESC, [schema],[name]
You need to login to post a comment.
