Skip to content

Latest commit

 

History

History
70 lines (58 loc) · 3.04 KB

end-begin-end-transact-sql.md

File metadata and controls

70 lines (58 loc) · 3.04 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom f1_keywords helpviewer_keywords dev_langs monikerRange
END (BEGIN...END) (Transact-SQL)
END (BEGIN...END) (Transact-SQL)
rwestMSFT
randolphwest
03/15/2017
sql
t-sql
reference
ignite-2024
END
END_TSQL
enclosing statements [SQL Server]
END keyword
BEGIN...END keyword
END (BEGIN...END) keyword
TSQL
>=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric

END (BEGIN...END) (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]

Encloses a series of [!INCLUDEtsql] statements that will execute as a group. BEGIN...END blocks can be nested.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

BEGIN   
     { sql_statement | statement_block }   
END   

Arguments

{ sql_statement| statement_block}
Is any valid [!INCLUDEtsql] statement or statement grouping as defined with a statement block. To define a statement block (batch), use the control-of-flow language keywords BEGIN and END. Although all [!INCLUDEtsql] statements are valid within a BEGIN...END block, certain [!INCLUDEtsql] statements should not be grouped together within the same batch (statement block).

Result Types

Boolean

Examples: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]

In the following example, BEGIN and END define a series of [!INCLUDEDWsql] statements that run together. If the BEGIN...END block are not included, the following example will be in a continuous loop.

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

See Also

ALTER TRIGGER (Transact-SQL)
BEGIN...END (Transact-SQL)
Control-of-Flow Language (Transact-SQL)
CREATE TRIGGER (Transact-SQL)
ELSE (IF...ELSE) (Transact-SQL)
IF...ELSE (Transact-SQL)
WHILE (Transact-SQL)