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.
BEGIN
{
sql_statement
| statement_block
}
END
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 being used.
In this example, BEGIN and END define a series of Transact-SQL statements that are to be executed 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
ALTER TRIGGER | CREATE TRIGGER |
Control-of-Flow Language | END (BEGIN...END) |