1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| CREATE TABLE ( nameinfo VARCHAR(500), rowsinfo BIGINT, reserved VARCHAR(20), datainfo VARCHAR(20), index_size VARCHAR(20), unused VARCHAR(20) );
DECLARE @tablename VARCHAR(255);
DECLARE Info_cursor CURSOR FOR SELECT '[' + [name] + ']' FROM sys.tables WHERE type = 'U';
OPEN Info_cursor; FETCH NEXT FROM Info_cursor INTO @tablename;
WHILE @@FETCH_STATUS = 0 BEGIN INSERT INTO EXEC sp_spaceused @tablename; FETCH NEXT FROM Info_cursor INTO @tablename; END;
CLOSE Info_cursor; DEALLOCATE Info_cursor;
CREATE TABLE [ ( TableName VARCHAR(50), DataInfo BIGINT, RowsInfo BIGINT, Spaceperrow AS (CASE RowsInfo WHEN 0 THEN 0 ELSE DataInfo / RowsInfo END ) PERSISTED );
INSERT INTO [ ( [TableName], [DataInfo], [RowsInfo] ) SELECT [nameinfo], CAST(REPLACE([datainfo], 'KB', '') AS BIGINT) AS 'datainfo', [rowsinfo] FROM ORDER BY CAST(REPLACE(reserved, 'KB', '') AS INT) DESC;
SELECT [tbspinfo].*, [tmptb].[Spaceperrow] AS '每行记录大概占用空间(KB)' FROM [ [ WHERE [tbspinfo].[nameinfo] = [tmptb].[TableName] ORDER BY CAST(REPLACE([tbspinfo].[reserved], 'KB', '') AS INT) DESC;
DROP TABLE [ DROP TABLE [
|