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       

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
猜你喜欢
  • 2022-02-21
  • 2021-06-28
  • 2021-04-16
  • 2021-06-12
  • 2021-07-31
  • 2021-07-15
相关资源
相似解决方案