国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
如何刪除非系統(tǒng)的表,存儲過程,自定義函數(shù),觸發(fā)器

/******執(zhí)行此操作時請慎重,確認無誤后把事務(wù)去掉既可******/
BEGIN TRAN --事務(wù) 開始

select * from sysobjects where (type='U' or type='P' or type='FN' or type='TR') and category<>2
declare @StrName nvarchar(200)
--刪除 函數(shù)
declare cursorFN cursor for
   select name from sysobjects where type='FN'
open cursorFN
while 1=1
begin
   fetch next from cursorFN into @StrName
   if @@fetch_status<>0 break
   exec('DROP FUNCTION '+@StrName)
end
close cursorFN
deallocate cursorFN

--刪除 存儲過程
declare cursorP2 cursor for
   select name from sysobjects where type='P' and category<>2
open cursorP2
while 1=1
begin
   fetch next from cursorP2 into @StrName
   if @@fetch_status<>0 break
   exec('DROP PROCEDURE '+@StrName)
end
close cursorP2
deallocate cursorP2

--刪除 表 (刪時自動刪除觸發(fā)器)
--1刪無約束無外鍵的表
declare cursorU1 cursor for
   select a.name from sysobjects a where not exists(select 1 from sysobjects b where a.id=b.parent_obj) and a.type='U'
open cursorU1
while 1=1
begin
   fetch next from cursorU1 into @StrName
   if @@fetch_status<>0 break
   exec('DROP TABLE '+@StrName)
end
close cursorU1
deallocate cursorU1

--2刪有約束或有外鍵的表
while exists(select 1 from sysconstraints)
begin
   declare cursorU2 cursor for
     select c.name from sysobjects c join (select distinct id from sysconstraints a
     where not exists(select 1 from sysforeignkeys b where a.id=b.rkeyid)) d on c.id=d.id where c.type='U'
   open cursorU2
   while 1=1
   begin
     fetch next from cursorU2 into @StrName
     if @@fetch_status<>0 break
     exec('DROP TABLE '+@StrName)
   end
   close cursorU2
   deallocate cursorU2
end
select * from sysobjects where (type='U' or type='P' or type='FN' or type='TR') and category<>2

ROLLBACK TRANSACTION --事務(wù) 回滾

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
sysobjects
SQL Server查詢代碼在哪個視圖、存儲過程、函數(shù)、觸發(fā)中使用過
SQL SERVER得到表、視圖、存儲過程、觸發(fā)器、字段的信息
sql 系統(tǒng)表介紹-sql server
觸發(fā)器
MSSQL中3個主要系統(tǒng)對象 sysdatabases、 sysobjects、 syscolumns
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服