DECLARE @TableName varchar();
CREATE TABLE #GetRecordingTempTable([id] [INT] IDENTITY(,) NOT NULL, [TableName] varchar() 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=)
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;
DROP TABLE #GetRecordingTempTable;
GO