Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"CREATE PROCEDURE SPNAME AS" vs. "CREATE PROCEDURE SPNAME AS BEGIN/END"

Tags:

tsql

When creating a stored procedure, does the BEGIN/END block serve and purpose?

eg,

CREATE PROCEDURE SPNAME
AS
  SELECT * FROM TABLE

vs.

CREATE PROCEDURE SPNAME
AS
BEGIN
  SELECT * FROM TABLE
END
like image 382
VJK Avatar asked Nov 16 '10 16:11

VJK


1 Answers

As indicated in the CREATE PROCEDURE documentation, the BEGIN/END is optional:

{ [ 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. For information, see the Best Practices, General Remarks, and Limitations and Restrictions sections that follow.

As a matter of personal preference, I always include them.

like image 68
Joe Stefanelli Avatar answered Sep 21 '22 14:09

Joe Stefanelli