Creating a stored procedure if it does not already exist

后端 未结 9 1008
谎友^
谎友^ 2021-02-05 01:12

I want to check if a list of stored procedures exist. I want this all to be done in 1 script, one by one. So far I have this format:

USE [myDatabase]
GO

IF NO         


        
9条回答
  •  迷失自我
    2021-02-05 01:38

    USE [myDatabase]
    GO
    
    IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'sp_1')
    BEGIN
      DROP PROCEDURE sp_1
    END
    GO   --<-- Add a Batch Separator here
    
    
    
    CREATE PROCEDURE sp_1
    AS
    .................
    END
    GO
    

提交回复
热议问题