declare @tbname varchar(50),
@sql nvarchar(1000)
--定义变量@tbname,@sql,@j
declare tbroy cursor for
select name from sysobjects as a
where xtype= 'u'
and SUBSTRING(name,0,3)='PM'
order by name
--定义游标,sysobjects为系统表,xtype= 'u'表示是用户表
open tbroy --填充游标
fetch next from tbroy into @tbname --提取游标
while @@fetch_status=0
begin
--select @sql='drop table '+@tbname
--exec sp_executesql @sql
exec ('drop table '+@tbname)
fetch next from tbroy into @tbname
end --while到and的内容看不懂,希望大家帮忙
close tbroy --关闭游标
deallocate tbroy