declare @tbname sysname set @tbname='sysobjects' --要查询的表名--游标处理 declare @s nvarchar(4000) set @s='declare tb cursor global --定义全局游标 for select name from '+@tbname+' where xtype=@xtype' exec sp_executesql @s,N'@xtype char(2)','S' open tb fetch tb close tb deallocate tb
set @tbname='sysobjects' --要查询的表名--游标处理
declare @s nvarchar(4000)
set @s='declare tb cursor global --定义全局游标
for
select name from '+@tbname+' where xtype=@xtype'
exec sp_executesql @s,N'@xtype char(2)','S'
open tb
fetch tb
close tb
deallocate tb