Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL STOP or ABORT command in SQL Server

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 to run it.

like image 984
Phillip Senn Avatar asked Jan 08 '10 14:01

Phillip Senn


People also ask

How do you abort a command in SQL?

To interrupt an Interactive SQL command: To interrupt an Interactive SQL command, select Interrupt the SQL Statement from the toolbar, or select SQL > Stop.

How do you end a SQL statement?

Terminating the statement before the WITH keyword with a semicolon will all it to execute without errors: ;WITH Ms AS (...) ... A MERGE statement must be terminated by a semi-colon (;).


1 Answers

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.

like image 114
Jed Avatar answered Sep 20 '22 17:09

Jed