SQLServer存储过程事务用法

更多资源:http://denghejun.github.io

IF object_id('InsertAntennaProcedure') IS NOT NULL DROP PROCEDURE InsertAntennaProcedure
GO CREATE PROCEDURE InsertAntennaProcedure
@INST_Model VARCHAR(36),
@INST_Manufacturer VARCHAR(36),
@INST_CalibrationDate datetime,
@INST_Pictures image
AS BEGIN
BEGIN TRANSACTION
BEGIN TRY
DECLARE @currentAntennaID INT;
INSERT INTO tb_Antenna (
INST_Model,
INST_Manufacturer,
INST_CalibrationDate,
INST_Pictures
)
VALUES
(
@INST_Model,
@INST_Manufacturer,
@INST_CalibrationDate,
@INST_Pictures
)
SELECT @currentAntennaID=IDENT_CURRENT('tb_Antenna') END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT; SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE(); -- Use RAISERROR inside the CATCH block to return error
-- information about the original error that caused
-- execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
END CATCH
IF @@TRANCOUNT > 0
COMMIT TRANSACTION;
END
GO EXEC InsertAntennaProcedure '', '', '2014-01-01',NULL;
上一篇:题解 CF191C 【Fools and Roads】


下一篇:CF191C Fools and Roads - 树剖解法