添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
年轻有为的葫芦  ·  sp_cursoropen ...·  1 周前    · 
逆袭的生菜  ·  JSON_ARRAYAGG ...·  4 周前    · 
曾经爱过的皮蛋  ·  ALTER AUTHORIZATION ...·  1 月前    · 
拉风的眼镜  ·  STRING_AGG ...·  1 月前    · 
魁梧的绿茶  ·  Project ERROR: Cannot ...·  3 周前    · 
个性的单杠  ·  NuGet Gallery ...·  6 月前    · 

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft Edge More info about Internet Explorer and Microsoft Edge Azure Synapse Analytics Analytics Platform System (PDW) SQL analytics endpoint in Microsoft Fabric Warehouse in Microsoft Fabric

Encloses a series of Transact-SQL statements so that a group of Transact-SQL statements can be executed in a logical block of code. BEGIN and END are control-of-flow language keywords.

Transact-SQL syntax conventions

Syntax

BEGIN
    { sql_statement | statement_block }

Arguments

{ sql_statement | statement_block }

Any valid Transact-SQL statement or statement grouping as defined by using a statement block.

Remarks

BEGIN...END blocks can be nested.

Although all Transact-SQL statements are valid within a BEGIN...END block, certain Transact-SQL statements shouldn't be grouped together within the same batch, or statement block.

Examples

In the following example, BEGIN and END define a series of Transact-SQL statements that execute together. If the BEGIN...END block isn't included, both ROLLBACK TRANSACTION statements would execute, and both PRINT messages would be returned.

USE AdventureWorks2022;
BEGIN TRANSACTION
IF @@TRANCOUNT = 0
BEGIN
    SELECT FirstName, MiddleName
    FROM Person.Person
    WHERE LastName = 'Adams';
    ROLLBACK TRANSACTION;
    PRINT N'Rolling back the transaction two times would cause an error.';
ROLLBACK TRANSACTION;
PRINT N'Rolled back the transaction.';

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

In the following example, BEGIN and END define a series of SQL statements that run together. If the BEGIN...END block isn't included, the following example runs in a continuous loop.

-- Uses AdventureWorksDW
DECLARE @Iteration INT = 0;
WHILE @Iteration < 10
BEGIN
    SELECT FirstName,
        MiddleName
    FROM dbo.DimCustomer
    WHERE LastName = 'Adams';
    SET @Iteration += 1;

  • ALTER TRIGGER (Transact-SQL)
  • Control-of-Flow Language (Transact-SQL)
  • CREATE TRIGGER (Transact-SQL)
  • END (BEGIN...END) (Transact-SQL)
  •