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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM