How to get all tables' size in Database

Pandians
Posted by Pandians under Sql Server category on | Views : 3058
Normally, We will use Sp_SpaceUsed system stored procedure to get table size. But. I want to get each tables size in the current database.
USE <DatabaseName>

CREATE TABLE #TableSize
(
TableName VARCHAR(100),
Records BIGINT,
Reserved VARCHAR(10),
Data VARCHAR(10),
Index_Size VARCHAR(10),
UnUsed VARCHAR(10)
)
GO

INSERT #TableSize
EXEC('sp_msforeachtable "sp_spaceused ''?''"')
GO

SELECT TableName,Records,Reserved,Data,Index_Size,UnUsed FROM #TableSize
GO

DROP TABLE #TableSize
GO

Cheers

Comments or Responses

Login to post response