T-SQL STOP or ABORT command in SQL Server

后端 未结 9 504
轻奢々
轻奢々 2021-01-01 08:44

Is there a command in Microsoft SQL Server T-SQL to tell the script to stop processing? I have a script that I want to keep for archival purposes, but I don\'t want anyone t

9条回答
  •  有刺的猬
    2021-01-01 09:09

    I know the question is old and was answered correctly in few different ways but there is no answer as mine which I have used in similar situations. First approach (very basic):

    IF (1=0)
    BEGIN
        PRINT 'it will not go there'
        -- your script here
    END
    PRINT 'but it will here'
    

    Second approach:

    PRINT 'stop here'
    RETURN
        -- your script here
    PRINT 'it will not go there'
    

    You can test it easily by yourself to make sure it behave as expected.

提交回复
热议问题