Sql Server批量删除数据表

最近做数据转移,由于误操作,在系统表master表里创建了N多表   实在是没法删

找到以下方法共享一下

--指定要删除的数据库中的表

use master
go

declare @sql varchar(8000),@TableName varchar(100)
begin
  declare cur cursor  for
  select Name from sysobjects where xtype='p'   --查询系统对象,即所有的表名,存储过程,函数等等
  open cur
  fetch next from cur into @TableName
  while @@fetch_status=0 
  begin
    set @sql='drop table '+@TableName    --DROP DEFAULT  PROCEDURE 根据删除对象类型对应调整,例如是存储过程的话 即drop procedure
    exec (@sql)
    fetch next from cur into @TableName
  end
  close cur
  deallocate cur
end


--select * from sysobjects where xtype='p' order by crdate

  

原文地址:https://www.cnblogs.com/YangFei-wow/p/4522580.html