如果可以使用SQLCMD模式,那么该咒语:on error exit(包括冒号)将导致RAISERROR实际上停止脚本。例如,:on error exitIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SOMETABLE]') AND type in (N'U')) RaisError ('This is not a Valid Instance Database', 15, 10)GOprint 'Keep Working'将输出:Msg 50000, Level 15, State 10, Line 3This is not a Valid Instance Database** An error was encountered during execution of batch. Exiting.批处理将停止。如果未打开SQLCMD模式,则将出现有关冒号的解析错误。不幸的是,它不是完全防弹的,就好像该脚本在未处于SQLCMD模式下运行时一样,SQL Managment Studio甚至在解析时间错误时都轻而易举!不过,如果您是从命令行运行它们,那很好。