--查询系统表,查看每张表的总行数
declare cur_tblName cursor for select name from sysobjects where type='U';
declare @tblName varchar(100);
declare @count int;
declare @sql nvarchar(4000);
open cur_tblName
FETCH NEXT FROM cur_tblName into @tblName
while @@FETCH_STATUS=0
begin
--这一个地方不知道是不是错了
set @sql=N'select @count=count(1) from'+ @tblName
print @sql
--这里也不知道是不是错了..
exec sp_executesql @sql,N'@count out',@count out
print '表名:'+@tblName+' 条数:'+cast(@count as varchar(100))
fetch next from cur_tblName into @tblName
end
close cur_tblName
deallocate cur_tblName
--------------------------------
打印出来的
select @count=count(1) fromspt_monitor
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_monitor' 附近有语法错误。
select @count=count(1) fromspt_values
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_values' 附近有语法错误。
select @count=count(1) fromspt_fallback_db
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_fallback_db' 附近有语法错误。
select @count=count(1) fromspt_fallback_dev
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_fallback_dev' 附近有语法错误。
select @count=count(1) fromspt_fallback_usg
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_fallback_usg' 附近有语法错误。
select @count=count(1) fromspt_provider_types
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_provider_types' 附近有语法错误。
select @count=count(1) fromspt_datatype_info_ext
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_datatype_info_ext' 附近有语法错误。
select @count=count(1) fromMSreplication_options
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromMSreplication_options' 附近有语法错误。
select @count=count(1) fromspt_datatype_info
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_datatype_info' 附近有语法错误。
select @count=count(1) fromspt_server_info
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'fromspt_server_info' 附近有语法错误。