小编典典

SQL Server中的T-SQL STOP或ABORT命令

sql

Microsoft SQL Server T-SQL中是否有命令告诉脚本停止处理?我有一个我想保留用于存档目的的脚本,但是我不希望任何人运行它。


阅读 248

收藏
2021-03-17

共1个答案

小编典典

另一种解决方案是使用以下GOTO语句来更改脚本的执行流程:

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!

警告!上面的示例来自我从美林奥尔德里奇(Merrill
Aldrich)获得的示例。在GOTO盲目执行该语句之前,建议您阅读他的有关T-SQL脚本中的流控制的教程。

2021-03-17