BEGIN/END Statements

Groups a series of SQL statements so that they can be treated as a single statement.

Syntax

BEGIN
    statement
    {statement
    {...}}
END

Syntax Elements

statement
Any supported SQL statement.

Comments

BEGIN and END statements are used to group the statements that form a procedure, and to allow the IF and WHILE statements to control multiple SQL statements.

Examples

CREATE PROC EX1 AS
BEGIN
-- currency conversion table
CREATE TABLE CONV (CID VARCHAR(5) PRIMARY KEY, RATE DECIMAL(5,2), CNAME VARCHAR(5))
-- test data table
CREATE TABLE TESTDATA (ID SMALLINT PRIMARY KEY, AMT DECIMAL(6,2))
END

Creates a procedure called EX1 that creates two tables. The two CREATE statements are grouped using a BEGIN/END block.

SET @I = 0
SET @V1 = SECOND(CURTIME())+1
WHILE @I<10
BEGIN
SET @I = @I+1
SET @V2 = @V1*@I + @V1/@I
INSERT INTO TESTDATA VALUES(@I,@V2)
END

Groups three statements together for execution in a loop.

See Also

CREATE PROCEDURE statement, IF statement, WHILE statement.