SQL Server查看所有表大小,所占空间
Posted 造飞机的程序员
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server查看所有表大小,所占空间相关的知识,希望对你有一定的参考价值。
CREATE TABLE #Data
(
name VARCHAR(100),
row VARCHAR(100),
reserved VARCHAR(100),
data VARCHAR(100),
index_size VARCHAR(100),
unused VARCHAR(100)
);
DECLARE @name VARCHAR(100);
DECLARE cur CURSOR FOR
SELECT name
FROM sysobjects
WHERE xtype = ‘u‘
ORDER BY name;
OPEN cur;
FETCH NEXT FROM cur
INTO @name;
WHILE @@fetch_status = 0
BEGIN
INSERT INTO #Data
EXEC sp_spaceused @name;
PRINT @name;
FETCH NEXT FROM cur
INTO @name;
END;
CLOSE cur;
DEALLOCATE cur;
CREATE TABLE #DataNew
(
name VARCHAR(100),
row INT,
reserved INT,
data INT,
index_size INT,
unused INT
);
INSERT INTO #DataNew
SELECT name,
CONVERT(INT, row) AS row,
CONVERT(INT, REPLACE(reserved, ‘KB‘, ‘‘)) AS reserved,
CONVERT(INT, REPLACE(data, ‘KB‘, ‘‘)) AS data,
CONVERT(INT, REPLACE(index_size, ‘KB‘, ‘‘)) AS index_size,
CONVERT(INT, REPLACE(unused, ‘KB‘, ‘‘)) AS unused
FROM #Data;
SELECT *
FROM #DataNew
ORDER BY data DESC;
DROP TABLE #Data,
#DataNew;
以上是关于SQL Server查看所有表大小,所占空间的主要内容,如果未能解决你的问题,请参考以下文章