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

标签 sql sql-server tsql sql-scripts

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

最佳答案

另一种解决方案可能是使用 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!

警告!上面的示例源 self 从 Merrill Aldrich 获得的示例。在你盲目地实现GOTO语句之前,我建议你阅读他关于Flow control in T-SQL Scripts的教程。 .

关于sql - SQL Server 中的 T-SQL STOP 或 ABORT 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2028072/

相关文章:

.net - 在 SQL Server 中共享来自单个数据库的程序集(模拟 GAC)

c# - Entity Framework : SELECT From Where ID NOT IN

sql - 计算派生表的 SQL Server ROW_NUMBER() OVER()

sql - postgresql : join with condition and without duplication

java - 数据库中的循环与应用程序中的循环

c# - TransactionScope 提前完成

SQL Server - 有条件地连接到任何不为空的表

asp.net - 将 varchar 转换为 int SQl server 2005

sql - 解决两个表之间的排序规则问题

sql - 'taking it offline' 进程失败后数据库无法访问