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

后端 未结 14 2361
囚心锁ツ
囚心锁ツ 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:30

    I would prefer to do it this way:

    • first generate the list of stored procedures to drop by inspecting the system catalog view:

      SELECT 'DROP PROCEDURE [' + SCHEMA_NAME(p.schema_id) + '].[' + p.NAME + '];'
      FROM sys.procedures p 
      

      This generates a list of DROP PROCEDURE statements in your SSMS output window.

    • copy that list into a new query window, and possibly adapt it / change it and then execute it

    No messy and slow cursors, gives you the ability to check and double-check your list of procedure to be dropped before you actually drop it

提交回复
热议问题