SQL Server 中的 T-SQL STOP 或 ABORT 命令 [英] T-SQL STOP or ABORT command in SQL Server

查看:50
本文介绍了SQL Server 中的 T-SQL STOP 或 ABORT 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

另一种解决方案是使用 GOTO 语句来改变脚本的执行流程...

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!

警告!上面的示例来自我从 Merrill Aldrich 获得的示例.在盲目地实施 GOTO 语句之前,我建议您阅读他关于 T-SQL 脚本中的流量控制.

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.

这篇关于SQL Server 中的 T-SQL STOP 或 ABORT 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆