What is anonymous block? [Resolved]

Posted by SurajRane under Sql Server on 6/21/2010 | Views : 14697 | Status : [Member] | Replies : 2
I was asked in infosys interview --

What is anonymous block? Do they exist in MS Sql Server?
and she also asked why we dont need to commit Stored procedures/triggers etc in Sql server


I told her answer for second question that that objects automatically committed but was not knowing first one.
anyone knows. please reply




Responses

Posted by: Vuyiswamb on: 6/21/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down

Resolved
I heard about something like that in Oracle not sql, i have googled a bit and i found this
http://www.orafaq.com/wiki/Anonymous_block

http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=/com.ibm.db2.luw.apdv.plsql.doc/doc/c0053848.html

Thank you for posting at Dotnetfunda
[Administrator]

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Deeraj on: 6/23/2010 [Member] Starter

Up
0
Down

Resolved

Yes anonymous blocks exist in SQL Server. Try the following from SSMS. An unnamed block of code that can be executed is an anonymous block. If we were to group a block of code we may endup writing a storedprocedure, function etc.


Begin
Select 'test'
End

Begin
Declare @i int;
Set @i=0;
While (@i<10)
Begin
Set @i=@i+1
Select CAST(@i as varchar)
Loop
End
End


Hope that helps!

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response