事务回滚添加

DECLARE @iErrorCount INT 

SET @iErrorCount = 0

SET XACT_ABORT ON

BEGIN TRAN Tran_Custom


INSERT/UPDATE/DELETE ....
SET @iErrorCount=@iErrorCount+@@error --加到增删改操作的后面 IF @iErrorCount=0 BEGIN COMMIT TRAN Tran_Custom END ELSE BEGIN ROLLBACK TRAN Tran_Custom END

你可能感兴趣的:(事务)