⟩ How To Use "BEGIN ... END" Statement Structures in MS SQL Server?
"BEGIN ... END" statement structure is used to group multiple statements into a single statement block, which can be used in other statement structures as a single statement. For example, a statement block can be used in an "IF ... ELSE ..." statement structure as a single statement.
The tutorial exercise below shows you how to use "BEGIN ... END" statement structures to place multiple statements into an "IF ... ELSE" statement structure:
DECLARE @site_name VARCHAR(40);
SET @site_name = 'SQA';
IF @site_name = 'DBA'
BEGIN
PRINT 'Dropping table: dba_links';
DROP TABLE dba_links;
END
ELSE IF @site_name = 'SQA'
BEGIN
PRINT 'Dropping table: sqa_links';
DROP TABLE sqa_links;
END
ELSE
PRINT 'Unknown site name: '+@site_name;
GO
Dropping table: sqa_links