SQL Server - stop or break execution of a SQL script
问题 Is there a way to immediately stop execution of a SQL script in SQL server, like a "break" or "exit" command? I have a script that does some validation and lookups before it starts doing inserts, and I want it to stop if any of the validations or lookups fail. 回答1: The raiserror method raiserror('Oh no a fatal error', 20, -1) with log This will terminate the connection, thereby stopping the rest of the script from running. Note that both severity level 20 or higher and the WITH LOG option are