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??
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.