Nested transactions in Sql Server

后端 未结 4 1056
情话喂你
情话喂你 2020-12-04 19:49

Imagine the following scenario:

I am using SQL Server 2005. I have a transaction that is calling, among other SQL statements, a stored procedure that also has a tran

4条回答
  •  长情又很酷
    2020-12-04 20:15

    I've tried with begin tran and commit inside the stored procedure say usp_test.
    Exec these sp with some other query as below

    update x set name='xxx'
    select * from x---contains 'xxx'
    begin tran
    update x set name='yyy'
    select * from x---contains 'yyy'
    exec usp_test
    select * from x---contains 'zzz' inside the sp
    rollback tran
    

    While executing the above query name in x table must be 'xxx' its not 'zzz' since the first begin tran rollbacked even the sp tran commit.
    So, first begin tran own the data changes.

提交回复
热议问题