BEGIN...END
用于定义一组一起执行的 Transact-SQL 语句,多见于IF...ELSE条件控制和WHILE循环控制
BREAK
退出 WHILE 循环内部的 WHILE 语句或 IF ELSE 语句最里面的循环
示例:
-- Uses AdventureWorks
WHILE ((SELECT AVG(ListPrice) FROM dbo.DimProduct) < $300)
BEGIN
UPDATE DimProduct
SET ListPrice = ListPrice * 2;
IF ((SELECT MAX(ListPrice) FROM dbo.DimProduct) > $500)
BREAK;
END
CONTINUE
重新开始 WHILE 循环
GOTO
将执行流更改到标签处。 跳过 GOTO 后面的 Transact-SQL 语句,并从标签位置继续处理。 GOTO 语句和标签可在过程、批处理或语句块中的任何位置使用
* GOTO语句可以潜嵌套
* GOTO 分支可跳转到定义在 GOTO 之前或之后的标签
* GOTO 语句的权限默认情况下授予任何有效用户
语法:
Define the label:
label:
Alter the execution:
GOTO label
示例:
DECLARE @Counter int;
SET @Counter = 1;
WHILE @Counter < 10
BEGIN
SELECT @Counter
SET @Counter = @Counter + 1
IF @Counter = 4 GOTO Branch_One --Jumps to the first branch.
IF @Counter = 5 GOTO Branch_Two --This will never execute.
END
Branch_One:
SELECT 'Jumping To Branch One.'
GOTO Branch_Three; --This will prevent Branch_Two from executing.
Branch_Two:
SELECT 'Jumping To Branch Two.'
Branch_Three:
SELECT '