Encloses a series of SQL statements so that control-of-flow language, such as if...else, can affect the performance of the whole group.
begin statement block end
is a series of statements enclosed by begin and end.
Without begin and end, the if condition would cause execution of only one SQL statement:
if (select avg (price) from titles) < $15 begin update titles set price = price * $2 select title, price from titles where price > $28 end
Without begin and end, the print statement would not execute:
create trigger deltitle on titles for delete as if (select count (*) from deleted, salesdetail where salesdetail.title_id = deleted.title_id) > 0 begin rollback transaction print "You can’t delete a title with sales." end else print "Deletion successful--no sales for this title."
begin...end blocks can nest within other begin...end blocks.
ANSI SQL – Compliance level: Transact-SQL extension.
begin...end permission defaults to all users. No permission is required to use it.
Commands if...else