简体   繁体   English

开始交易…提交交易问题

[英]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.

相关问题 COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION - The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION SQLException - 事务BEGIN / COMMIT不匹配 - SQLException - Transaction BEGIN / COMMIT mismatch IMPLICIT TRANSACTIONS ON / OFF和BEGIN / COMMIT交易 - IMPLICIT TRANSACTIONS ON/OFF and BEGIN /COMMIT Transaction 交易提交? - transaction commit? EXECUTE之后的事务计数表明BEGIN和COMMIT语句的数量不匹配 - Transaction count after EXECUTE indicates mismatching number of BEGIN and COMMIT statements EXECUTE之后的事务计数表明BEGIN和COMMIT?的数量不匹配? - Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT? 消息3902,级别16,状态1. COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION - Msg 3902, Level 16, State 1. The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION 收到错误:COMMIT TRANSACTION请求在SQL脚本中没有相应的BEGIN TRANSACTION - Receiving an error: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION in SQL Script Sybase与SQL Server的BEGIN TRANSACTION…ROLLBACK或COMMIT TRANSACTION有何相似之处? - What is the Sybase analog to Sql Server's BEGIN TRANSACTION … ROLLBACK or COMMIT TRANSACTION? 开始交易未定义 - Begin Transaction not defined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM