Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2012-08-13 : 09:01:34
|
first of all, i'm new to sql OR stored procedure.while reading online examples, i notice that in some examples there is [begin] and [end] and in some there is nothing as below.create procedure newprocedureasselect * from table1GO with [begin] and [end]create procedure newprocedureasBEGINselect * from table1ENDGO I wonder when we use [begin] and [end] and when we should not use them. |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-13 : 09:16:54
|
| For stored procedures it is optional. But, in some other cases, it is mandatory - for example, for a scalar function you have to have the begin and end. If you use IF/ELSE constructs and if you have more than one statement in the IF block, you will need a begin and end in the if block etc.In many cases, you can tell whether it is mandatory or not by examining the MSDN page and looking to see if the BEGIN/END are in square brackets - for example, here it is in square brackets:http://msdn.microsoft.com/en-us/library/ms187926.aspxHere it is not (hence mandatory) http://msdn.microsoft.com/en-us/library/ms186755.aspx |
 |
|
|
|
|
|