T-SQL: Table Sizes in SQL Server
--one table
sp_spaceused 'TABLE_NAME'
--all tables
EXEC sp_MSforeachtable 'EXEC sp_spaceused ''?'''
--OR
IF OBJECT_ID('tempdb..#TableSize') IS NOT NULL
DROP TABLE #TableSize
CREATE TABLE #TableSize
(
SEQ INT IDENTITY(1,1) ,
name NVARCHAR(200),
rows BIGINT,
reserved VARCHAR(100),
data VARCHAR(100),
index_size VARCHAR(100),
unused VARCHAR(100)
)
INSERT #TableSize
EXEC sp_MSforeachtable 'EXEC sp_spaceused ''?'''
SELECT* FROM #TableSize
See Also
- [[Transact-SQL Portal]]