Sqlserver事务写法模板

事务的写法模板

BEGIN TRANSACTION;

BEGIN TRY

。。。。

COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
DECLARE @ErrorMessage   nvarchar(4000);
DECLARE @ErrorSeverity  int;
DECLARE @ErrorState     int;

SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR (
@ErrorMessage,    — Message text.
@ErrorSeverity,    — Severity.
@ErrorState — State.
)
END CATCH