在我的事务中添加显式提交
与自动提交有什么区别吗?
CREATE TABLE #test (test_col INT)
使用明确的 COMMIT
INSERT #test
VALUES (11)
BEGIN TRY
BEGIN TRAN DELETE_TRAN
DELETE FROM #test
COMMIT TRAN DELETE_TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN DELETE_TRAN
SELECT ERRORMESSAGE = Error_message()
END CATCH
SELECT *
FROM #test
没有显式提交
INSERT #test
VALUES (11)
BEGIN TRY
BEGIN TRAN DELETE_TRAN
DELETE FROM #test
END TRY
BEGIN CATCH
ROLLBACK TRAN DELETE_TRAN
SELECT ERRORMESSAGE = Error_message()
END CATCH
SELECT *
FROM #test
这两种方法都可以实现相同的功能。有人能告诉我它们之间有什么区别或者优劣吗?