Profile photo
Submitted by Bikram Shrestha
on September 14th, 2011 at 10:45:47 EST

BEGIN END block in stored procedure. Do I always need to use it?

I have a question. I am creating stored procedure in MS SQL Server. Do I always need to use BEGIN END statement block even for simple stored proc.
For example:
Select * from MyTable;

Any thoughts?

Profile photo
Replied by SBajra
on September 19th, 2011 at 15:46:25 EST
BEGIN END is for marking a block of statements like { } in C#.
You do not need to start your stored procedure with BEGIN END if it is simple as you said. But its just coding practice that some prefer vs others. However, for IF statement, I would always prefer BEGIN and END statements.

So, to answer your question is NO, you do not need BEGIN & END for simple stored procedure.
Accepted Answer

Profile photo
Replied by Bikram Shrestha
on September 20th, 2011 at 08:16:27 EST
Thanks for clarification.