How to drop all stored procedures at once in SQL Server database?

后端 未结 14 2056
囚心锁ツ
囚心锁ツ 2021-01-29 22:53

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\'[         


        
14条回答
  •  暖寄归人
    2021-01-29 23:34

    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
    

提交回复
热议问题