一、
BEGIN TRANSACTION A
--SAVE TRANSACTION A
INSERT INTO Holiday
(HolidayDate,[Year])
VALUES(GETDATE(),2022)
INSERT INTO Holiday
(HolidayDate,[Year])
VALUES(NULL,2022)
IF @@ERROR=0 --如果前一个Transact-SQL 语句执行没有错误,则返回0。
COMMIT TRANSACTION A
ELSE
ROLLBACK TRANSACTION A
二、
BEGIN TRY
BEGIN TRANSACTION A
INSERT INTO Holiday
(HolidayDate,[Year])
VALUES(GETDATE(),2022)
INSERT INTO Holiday
(HolidayDate,[Year])
VALUES(NULL,2022)
COMMIT TRANSACTION A
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION A
END CATCH