トランザクションを正しく使用してデータをコミットし、ロールバック
1550 ワード
CREATE TABLE test1(
fid VARCHAR(2) NULL
)
BEGIN TRY
BEGIN
TRAN
INSERT INTO test1(fid) VALUES('1')
INSERT INTO test1(fid) VALUES('222')
INSERT INTO test1(fid) VALUES('3')
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT>0
ROLLBACK TRANSACTION
/*
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage
*/
END CATCH