我必须从多个表中插入和删除,并且我想在一个存储过程中完成所有这些操作,因此我可以拥有如下所示的多个事务块,以及在每个事务中处理错误的最佳方法。请告知
BEGIN TRANSACTION [TRANS1]
BEGIN TRY
Insert into ArchiveTable select * from Completed (nolock)
delete from Completed(nolock) where convert(date,LastModified,101) > getdate()
COMMIT TRANSACTION [TRANS1]
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION [TRANS1]
PRINT ERROR_MESSAGE()
END CATCH
BEGIN TRANSACTION [TRANS2]
BEGIN TRY
Insert into ArchiveTable2 select * from New (nolock)
delete from New (nolock) where convert(date,LastModified,101) > getdate()
COMMIT TRANSACTION [TRANS2]
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION [TRANS2]
PRINT ERROR_MESSAGE()
END CATCH