Sunday, November 7, 2010

Fun With TRANSACTION

What will be the output of the SELECT statement in the following query?

DECLARE @Table TABLE ([ID] INT IDENTITY(1,1), [Name] VARCHAR(10))
INSERT @Table ([Name]) VALUES ('Hari')
BEGIN TRANSACTION Test
INSERT  @Table ([Name]) VALUES ('Jon')
INSERT @Table ([Name]) VALUES ('Peter')
ROLLBACK TRANSACTION Test
INSERT @Table ([Name]) VALUES ('Max')
SELECT [ID],[Name] FROM @Table

Option1:
Option2:
Option3:
Option4:
None of the above.




Table variables do not participate in transactions so you can rollback a transaction without affecting the table variable. In our case, the insert inside the transaction is not rolled back.

No comments:

Post a Comment