SET NOCOUNT ON DECLARE @db VARCHAR(20) SET @db=db_name() DBCC UPDATEUSAGE(@db) WITH NO_INFOMSGS GO CREATE TABLE #tblSpace ( 数据表名称 varchar(250) null, 记录笔数 int null, 保留空间 varchar(15) null, 数据使用空间 varchar(15) null, 索引使用空间 varchar(15) null, 未使用空间 varchar(15) null ) DECLARE @tblname varchar(250) DECLARE curTbls CURSOR FOR SELECT TABLE_NAME FROM Information_Schema.TABLES WHERE TABLE_TYPE='BASE TABLE' OPEN CurTbls FETCH NEXT FROM curTbls INTO @tblName WHILE @@FETCH_STATUS=0 BEGIN INSERT #tblSpace EXEC sp_spaceused @tblName FETCH NEXT FROM curTbls INTO @tblName END CLOSE CurTbls DEALLOCATE curTbls SELECT * FROM #tblSpace ORDER BY 记录笔数 DESC DROP TABLE #tblSpace