Rob
Rob

Reputation: 638

Begin Transaction ... Commit Transaction Issue

i have a question regarding using Transaction. Consider this code:

declare @trans_name varchar(max) = 'Append'
begin tran @trans_name
    insert into SIDB_Module
    (module_name, module_description, modulelevel, parentid, issystem, iscurrent)
    values
    (@module_name, @module_description, @modulelevel, @parentid, @issystem, 1)
    set @moduleid = SCOPE_IDENTITY()
    declare @id int = OBJECT_ID('SIDB_Module')
    exec usp_M_SIDB_TransactionInformation_App_Append
        @moduleid, id, 'append' ,@createdby_userid
if @@ERROR <> 0
rollback tran @trans_name
commit tran @trans_name

does transaction still apply on this.. even the next insert query is on the other stored procedure??

Upvotes: 0

Views: 540

Answers (1)

gbn
gbn

Reputation: 432180

Yes, the call to usp_M_SIDB_TransactionInformation_App_Append is part of the transaction

Note: your error handling is "old style" (using @@ERROR) from SQL Server 2000 and will generate errors (error 266) if the inner proc rolls back or commits.

For more, see Nested stored procedures containing TRY CATCH ROLLBACK pattern?

Upvotes: 3

Related Questions