请帮我调下这段SQL:统计每个表的行数
xzzxg 2003-08-21 10:09:45 这段SQL的库无关,放哪个库都能执行,但有错误
Drop table ##Temp
CREATE TABLE ##Temp (
[TableName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[RowsCount] [int] NULL ,
)
DECLARE @TableName nvarchar(20)
declare @Rows int
declare TempCur cursor static for
select name from sysobjects where type='U'
open TempCur
FETCH NEXT FROM TempCur INTO @TableName
WHILE(@@FETCH_STATUS=0)
BEGIN
exec('select @Rows = count(*) from ' + @TableName)
exec('Insert into ##Temp Values(' + @TableName + ',' + @Rows + ')')
FETCH NEXT FROM TempCur INTO @TableName
END
CLOSE TempCur
DEALLOCATE TempCur
select * from ##Temp