IF OBJECT_ID('tempdb..#TablesSizes') IS NOT NULL
DROP TABLE #TablesSizes
CREATE TABLE #TablesSizes
(
TableName sysname ,
Rows BIGINT ,--数据量
reserved VARCHAR(100) ,--预留空间
data VARCHAR(100) , --数据大小
index_size VARCHAR(100) ,--索引大小
unused VARCHAR(100)--未使用空间
)
DECLARE @sql VARCHAR(MAX)
SELECT @sql = COALESCE(@sql, '') + '
INSERT INTO #TablesSizes execute sp_spaceused ''' + QUOTENAME(TABLE_SCHEMA,
'[]') + '.'
+ QUOTENAME(Table_Name, '[]') + ''''
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
PRINT ( @SQL )
EXECUTE (@SQL)
SELECT *
FROM #TablesSizes
ORDER BY Rows DESC