篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL事务示例2相关的知识,希望对你有一定的参考价值。
CREATE PROCEDURE [dbo].[usp_SomeSP]
@SomeData XML,
@ReturnCode INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ErrorCode INT = 0;
SET @ReturnCode = 0;
BEGIN TRANSACTION;
-- YOUR SQL CODE
SELECT @ErrorCode = @@ERROR;
IF ( @ErrorCode <> 0 )
GOTO ERROR_POINT;
COMMIT TRANSACTION;
ERROR_POINT:
IF ( @ErrorCode <> 0 )
BEGIN
ROLLBACK TRANSACTION;
SET @ReturnCode = @ErrorCode;
END;
PRINT @ReturnCode;
END;