|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
p0peye (9/23/2010) Please correct me if i am wrong...
My understanding is, you wont be able to commit or rollback inner transaction separately as the outer transaction will override with its commit/rollback command. If this is true, why do we need to use nested transactions or in which scenario nested transactions can be used?
let me know if my question is not clear
_________ Andrew
Having the ability to nest transactions is necessary for stored procedures that might call other stored procedures. Each one might have it's own transaction embedded in the code. Otherwise, it's not really necessary to nest them like in the example.
This was a good question. I debated between the first and last choices and ultimately picked the wrong one. I wasn't sure because I knew that the inner commits are ignored and only the outer transaction really means anything. If you commit the outer transaction, all inner transactions are also committed. If you rollback the outer transaction, all inner transactions are also rolled back (regardless if you committed the inner transaction or not).
This one had a rollback in the inner transaction so I also ignored that one and assumed everything would be rolled back anyway -- WRONG! Causes an error because you cannot rollback inner transactions.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:53 AM
Points: 1,530,
Visits: 359
|
|
thanks, i was looking for an explaination wherein we save the inner transaction...
tommyh (9/23/2010)
p0peye (9/23/2010) Please correct me if i am wrong...
My understanding is, you wont be able to commit or rollback inner transaction separately as the outer transaction will override with its commit/rollback command. If this is true, why do we need to use nested transactions or in which scenario nested transactions can be used?
let me know if my question is not clear
_________ AndrewNow this is a bit out off my league. But i would say that your partly correct. You cant commit an inner transaction and then later rollback the outer one. You can however using "save transaction" rollback a part and then commit the rest. Like this create table #TransTest (i integer)
begin tran OuterTran insert into #TransTest (i) values (1)
save tran InnerTran insert into #TransTest (i) values (2) rollback tran InnerTran
commit tran OuterTran
select * from #TransTest
drop table #TransTest
Here only one value is inserted into the table the second row is rolled back. /T
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 1:10 PM
Points: 2,673,
Visits: 2,418
|
|
| Good question. Ahh......the subtleties of SQL Server. Thanks.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
looking at the options, I thought option one would be the right answer. Since both inner and outer rollback, query would return zero rows.
then executed it and got right answer.
Thanks for all questions on rollback series .
SQL DBA.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:22 AM
Points: 551,
Visits: 1,150
|
|
Great series of questions. Although, I think the correct answer is actually option 1 and option 3. IE
The following error is raised "Cannot roll back InnerTran. No transaction or savepoint of that name was found." and All transactions are rolled back and an empty recordset is returned.
Now, if you had SET XACT ABORT ON then it would have just been option 3 as the batch would abort and the select would not be executed. Lucky, I figured you were looking for the error so I chose option 3 and got it right.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 18,754,
Visits: 12,337
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Monday, August 13, 2012 10:04 AM
Points: 554,
Visits: 861
|
|
| Thanks for the nice Question :)
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, April 02, 2013 8:28 PM
Points: 555,
Visits: 2,137
|
|
thank you for the question and thanks to all the people that gived more examples to explain it because I have read the microsoft explanation but my comprehension of it was somewhat wrong
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877,
Visits: 1,159
|
|
Good series of questions Nakul. Thanks
Thanks
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Monday, March 11, 2013 4:12 AM
Points: 664,
Visits: 138
|
|
Perfect explanation and example .

|
|
|
|