declare @na varchar(100)
declare cur cursor local for
select name from sys.objects where type='u'
open cur
fetch next from cur into @na
if @@fetch_status=0
begin
select @na,count(*) from @na
fetch next from cur into @na
end
close cur
deallocate cur
消息 156,级别 15,状态 1,第 11 行
关键字 'as' 附近有语法错误。
------解决方案--------------------
这个IF好像应该改成WHILE
否则定义游标只执行一次无意义
------解决方案--------------------
查表记录数没必要游标这么麻烦,以下语句一次返回记录数
- SQL code
SELECT OBJECT_NAME(ID) AS TABLENAME ,ROWSFROM SYSINDEXESWHERE INDID < 2