您的位置:首页 > 博客中心 > 数据库 >

批量删除Sql Server数据表

时间:2022-03-14 09:35

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

找到以下方法共享一下

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

use master
go

declare @sql varchar(8000),@TableName varchar(100)
begin
  declare cur cursor  for
  select Name from sysobjects where xtype=‘p‘ and crdate>=‘2015-03-31 10:33:14.663‘
  open cur
  fetch next from cur into @TableName
  while @@fetch_status=0 
  begin
    set @sql=‘drop table ‘+@TableName    --DROP DEFAULT  PROCEDURE
    exec (@sql)
    fetch next from cur into @TableName
  end
  close cur
  deallocate cur
end


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

  

本类排行

今日推荐

热门手游