T-SQL STOP or ABORT command in SQL Server

后端 未结 9 501
轻奢々
轻奢々 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:00

    An alternate solution could be to alter the flow of execution of your script by using the GOTO statement...

    DECLARE  @RunScript bit;
    SET @RunScript = 0;
    
    IF @RunScript != 1
    BEGIN
    RAISERROR ('Raise Error does not stop processing, so we will call GOTO to skip over the script', 1, 1);
    GOTO Skipper -- This will skip over the script and go to Skipper
    END
    
    PRINT 'This is where your working script can go';
    PRINT 'This is where your working script can go';
    PRINT 'This is where your working script can go';
    PRINT 'This is where your working script can go';
    
    Skipper: -- Don't do nuttin!
    

    Warning! The above sample was derived from an example I got from Merrill Aldrich. Before you implement the GOTO statement blindly, I recommend you read his tutorial on Flow control in T-SQL Scripts.

提交回复
热议问题