[英]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?? 事务是否仍然适用于此。即使下一个插入查询也位于其他存储过程上?
Yes, the call to usp_M_SIDB_TransactionInformation_App_Append
is part of the transaction 是的,对
usp_M_SIDB_TransactionInformation_App_Append
的调用是事务的一部分
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. 注意:您的错误处理是SQL Server 2000中的“旧样式”(使用@@ ERROR),如果内部proc回滚或提交,将生成错误(错误266)。
For more, see Nested stored procedures containing TRY CATCH ROLLBACK pattern? 有关更多信息,请参见包含TRY CATCH ROLLBACK模式的嵌套存储过程?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.