--如何得到一个数据库中每个表格的数据数目?

USE Forums -- 可改成您的数据库名称
SET NOCOUNT ON

DECLARE @tables_cursor CURSOR 7
set @tables_cursor=Cursor FOR
SELECT name FROM sysobjects WHERE type = 'U'
OPEN @tables_cursor
DECLARE @tablename varchar(30), @quote char(1)
SELECT @quote = ''''

FETCH NEXT FROM @tables_cursor INTO @tablename
WHILE (@@fetch_status <> -1)
BEGIN
EXEC ('Select ' + @quote+'Rows in ' + @tablename + ' = '+ @quote + ', count(*) from '+ @tablename)
FETCH NEXT FROM @tables_cursor INTO @tablename
END
DEALLOCATE @tables_cursor
SET NOCOUNT OFF

转载于:https://www.cnblogs.com/flashccie/archive/2005/11/06/269813.html

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐