标签:har status next declare sed for dea etc begin
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;
标签:har status next declare sed for dea etc begin
原文地址:https://www.cnblogs.com/Cruise-Yang/p/9327388.html