TSQL - SQL server Query to get Table ,index ,filegroup , and spaceused

SELECT
t
.NAME AS TableName,i.name AS indexName,ds.name AS filegroup_name ,SUM(p.rows) AS RowCounts,SUM(a.total_pages) AS TotalPages,
SUM(a.used_pages) AS UsedPages,
SUM(a.data_pages) AS DataPages,(
SUM(a.total_pages) * 8) / 1024 AS TotalSpaceMB, (SUM(a.used_pages) * 8) / 1024 AS UsedSpaceMB, (SUM(a.data_pages) * 8) / 1024 AS DataSpaceMBFROM
sys.tables tINNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_idINNER JOIN sys.filegroups ds ON i.data_space_id=ds.data_space_id INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_idINNER JOIN
sys.allocation_units a ON p.partition_id = a.container_idWHERE t
.NAME NOT LIKE 'dt%' ANDi.OBJECT_ID > 255 AND i
.index_id <= 1GROUP BY t
.NAME, i.object_id, i.index_id, i.name ,ds.nameORDER BY
OBJECT_NAME(i.object_id)

Comments

Popular posts from this blog

SSAS : A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running. (Microsoft.AnalysisServices.AdomdClient). + Solution

SSIS Error : Unable to infer the XSD from the XML file. The XML contains multiple namespaces