Skip to content

Latest commit

 

History

History
79 lines (63 loc) · 3.12 KB

File metadata and controls

79 lines (63 loc) · 3.12 KB
title END (BEGIN...END) (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 03/15/2017
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
END
END_TSQL
dev_langs
TSQL
helpviewer_keywords
enclosing statements [SQL Server]
END keyword
BEGIN...END keyword
END (BEGIN...END) keyword
ms.assetid 354c4935-1375-4141-8195-61326662f4d2
caps.latest.revision 34
author BYHAM
ms.author rickbyh
manager jhubbard

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

[!INCLUDEtsql-appliesto-ss2008-all_md]

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

Topic link icon Transact-SQL Syntax Conventions

Syntax

-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
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: [!INCLUDEssSDWfull] 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)