本文介紹了如何一次刪除 SQL Server 數(shù)據(jù)庫中的所有存儲過程?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
目前我們?yōu)槟_本文件中的每個存儲過程使用單獨的 drop 語句:
Currently we use separate a drop statements for each stored procedure in the script file:
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[MySP]')
AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[MySP]
有沒有辦法一次性刪除它們,或者循環(huán)刪除它們?
Is there a way to drop them all at once, or maybe in a loop?
推薦答案
Something like (Found at 使用 SQL Server 中的存儲過程從數(shù)據(jù)庫中刪除所有過程).
Something like (Found at Delete All Procedures from a database using a Stored procedure in SQL Server).
順便說一句,這似乎是一件非常危險的事情,只是一個想法......
Just so by the way, this seems like a VERY dangerous thing to do, just a thought...
declare @procName varchar(500)
declare cur cursor
for select [name] from sys.objects where type = 'p'
open cur
fetch next from cur into @procName
while @@fetch_status = 0
begin
exec('drop procedure [' + @procName + ']')
fetch next from cur into @procName
end
close cur
deallocate cur
這篇關(guān)于如何一次刪除 SQL Server 數(shù)據(jù)庫中的所有存儲過程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!