电脑技术学习

如何才能保障存储过程嵌套调用的原子性

dn001

此代码用于解决存储过程间嵌套调用时的全局原子性问题:

DECLARE @TranStartedbit
SET @TranStarted = 0
IF( @@TRANCOUNT = 0 ) -- 用于嵌套
BEGIN
BEGIN TRANSACTION
SET @TranStarted = 1
END
ELSE
SET @TranStarted = 0
.....
IF( @TranStarted = 1 )
BEGIN
SET @TranStarted = 0
COMMIT TRANSACTION
END