Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize

BEGIN...END

SQL Server 2000

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

Syntax

BEGIN
    {
        sql_statement
        
| statement_block
    }
END

Arguments

{ sql_statement | statement_block }

Is any valid Transact-SQL statement or statement grouping as defined with 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 should not be grouped together within the same batch (statement block). For more information, see Batches and the individual statements used.

Examples

In this example, BEGIN and END define a series of Transact-SQL statements that execute together. If the BEGIN...END block were not included, the IF condition would cause only the ROLLBACK TRANSACTION to execute, and the print message would not be returned.

USE pubs
GO
CREATE TRIGGER deltitle
ON titles
FOR delete
AS
IF    (SELECT COUNT(*) FROM deleted, sales
      WHERE sales.title_id = deleted.title_id) > 0
   BEGIN
      ROLLBACK TRANSACTION
      PRINT 'You can't delete a title with sales.'
END

See Also

ALTER TRIGGER

Control-of-Flow Language

CREATE TRIGGER

END (BEGIN...END)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft