码迷,mamicode.com
首页 > 其他好文 > 详细

统计整个库所有表的记录数

时间:2014-07-06 15:33:44      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   for   

DECLARE @TableName VARCHAR(119)
CREATE TABLE #GetRecordingTempTable([id] [INT] IDENTITY(1,1) NOT NULL, [TableName] varchar(255) NOT NULL, [RecordingCount] INT);
DECLARE Table_Cursor CURSOR FOR SELECT [name] FROM sysobjects WHERE xtype=U;
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor INTO @TableName;
WHILE(@@FETCH_STATUS=0)
BEGIN
EXEC(INSERT INTO #GetRecordingTempTable ([TableName],[RecordingCount]) SELECT ‘‘‘+@TableName+‘‘‘, COUNT(0) FROM [+@TableName+];);
FETCH NEXT FROM Table_Cursor INTO @TableName;
END
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;
SELECT [TableName] AS [表名称],[RecordingCount] AS [总记录数] FROM #GetRecordingTempTable ORDER BY [RecordingCount] DESC;
DROP TABLE #GetRecordingTempTable;

 

统计整个库所有表的记录数,布布扣,bubuko.com

统计整个库所有表的记录数

标签:des   style   blog   color   os   for   

原文地址:http://www.cnblogs.com/dashi/p/3825454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!