Are BEGIN / END keywords required in a stored procedure?
Solution 1
They are optional.
From MSDN - CREATE PROCEDURE:
From the definition of the command -
AS { [ BEGIN ] sql_statement [;] [ ...n ] [ END ] }
And later on in the page:
{ [ BEGIN ] sql_statement [;] [ ...n ] [ END ] }
One or more Transact-SQL statements comprising the body of the procedure. You can use the optional BEGIN and END keywords to enclose the statements.
Solution 2
As indicated in the CREATE PROCEDURE documentation, they are optional.
{ [ BEGIN ] sql_statement [;] [ ...n ] [ END ] }
One or more Transact-SQL statements comprising the body of the procedure. You can use the optional [emphasis added] BEGIN and END keywords to enclose the statements. For information, see the Best Practices, General Remarks, and Limitations and Restrictions sections that follow.
Personally, I always include them, but that's just me.
JJ.
Updated on October 03, 2020Comments
-
JJ. almost 4 years
Possible Duplicate:
When do I need to use Begin / End Blocks and the Go keyword in SQL Server?Example:
CREATE PROCEDURE DoSomething AS BEGIN SET NOCOUNT ON; -- Insert lots of statements in here, including other stored procedures. END
Do you need the BEGIN and END? Does it make ANY difference if you have them or not?