How to forcibly create stored procedure even if some error occurs?

后端 未结 1 1078
春和景丽
春和景丽 2021-01-20 19:55

When I execute database script, I got errors in stored procedure then it couldn\'t create that stored procedure that have errors. I want to forcibly create stored procedure

1条回答
  •  太阳男子
    2021-01-20 20:32

    You can force the creation of a stored procedure by creating it in a can't-fail way. See this example:

    if object_id('sp_name') is null
        exec sp_executesql N'create procedure dbo.sp_name as select 1'
    go
    alter procedure db.sp_name
    as
    ...
    go
    

    Now if the alter fails, there will be a stored procedure anyway.

    0 讨论(0)
提交回复
热议问题