基本上我想保持事务非常简单,但是如果在后面的部分中发生任何错误,我应该能够回滚。 类似的东西:
BEGIN TRANSACTION
DELETE SET 1(this will delete first set of table)
COMMIT
DELETE SET 2 (will delete second set of table)
如果在删除set 2时发生任何错误,我也应该能够回滚set 1事务。如果我们有任何选择可以这样做,请告诉我。感谢您的帮助。
答案 0 :(得分:2)
如果删除set时发生任何错误 2我应该能够回滚第1组 交易也是如此。让我知道,如果我们 有这样的选择。 感谢您的帮助。
然后,你为什么不这样做?
BEGIN TRY
BEGIN TRANSACTION -- Start the transaction
DELETE SET 1(this will delete first set of table)
DELETE SET 2 (will delete second set of table)
-- If we reach here, success!
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY()
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH
阅读here以获取完整说明。
答案 1 :(得分:-2)
如果你的意思是删除表,就像删除表(即表,而不是内容)一样,你运气不好 - 不处理DDL。