MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
is it any way to avoid Rollbacking of inner transactions?? - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

is it any way to avoid Rollbacking of inner transactions??

Last post 08-19-2008 5:30 AM by srinivasanrr_wiz. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 08-05-2008 7:14 AM

    is it any way to avoid Rollbacking of inner transactions??

     I am having doubt - is it achivable Or not? The senario is ,
    "If the outer transaction is rolled back, then all inner transactions are also rolled back"
    is it any way to avoid Rollbacking of inner transactions??

     

    Thanks,

    srinivasan r 

  • 08-06-2008 6:35 AM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 73

    Re: is it any way to avoid Rollbacking of inner transactions??

    Your are correct that if the outer transaction is rolled back all of the inner transactions are also rolled back.

  • 08-08-2008 12:01 AM In reply to

    Re: is it any way to avoid Rollbacking of inner transactions??

     Yes.but My Question is - "is there anyway to avoid Rollbacking of inner transactions alone??"

  • 08-08-2008 1:11 PM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 73

    Re: is it any way to avoid Rollbacking of inner transactions??

    There does not seem to be a way to do this.

  • 08-08-2008 11:23 PM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 296

    Re: is it any way to avoid Rollbacking of inner transactions??

    If I understand your question correctly, you can achieve this using savepoints 

     if object_id('mytable') is not null
       drop table mytable
    go
    create table mytable (mycol char(1))
    go

    -- Outer tran
    begin tran tran1
    insert mytable select '1'
    save tran save1

       -- inner tran
       begin tran tran2
       insert mytable select '2'
       save tran save2

         -- another inner tran
         begin tran tran3
         insert mytable select '3'
         save tran save3
        

    -- some error occurred; rollback up to savepoint 2
    rollback tran save2


    select open_tran from master.dbo.sysprocesses where spid = @@spid

    -- commit all work [Amended to close all open transactions]
    if @@trancount <> 0
    begin
      commit tran tran1
      commit tran tran2
      commit tran tran3
    end

    select * from mytable
    select open_tran from master.dbo.sysprocesses where spid = @@spid


  • 08-19-2008 5:30 AM In reply to

    Re: is it any way to avoid Rollbacking of inner transactions??

     Hi aprato,

               Thanks for your reply. i will try this out.

Page 1 of 1 (6 items)