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.
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
An alternate solution could be to alter the flow of execution of your script by using the
GOTO
statement...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.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):
Second approach:
You can test it easily by yourself to make sure it behave as expected.
Try running this as a TSQL Script
The return ends the execution.
RETURN (Transact-SQL)
Why not simply add the following to the beginning of the script
RAISERROR with severity 20 will report as error in Event Viewer.
You can use SET PARSEONLY ON; (or NOEXEC). At the end of script use GO SET PARSEONLY OFF;
To work around the RETURN/GO issue you could put
RAISERROR ('Oi! Stop!', 20, 1) WITH LOG
at the top.This will close the client connection as per RAISERROR on MSDN.
The very big downside is you have to be sysadmin to use severity 20.
Edit:
A simple demonstration to counter Jersey Dude's comment...