BEGIN TRANSACTION TranName update.... delete .... IF (@@ERROR <>0) ROLLBACK TRANSACTION TranName ELSE COMMIT TRAN TranName
begin trandelete from table_Pqs where ...... if @@error<>0 goto errdelete from table_Pqh where ...... if @@error<>0 goto errdelete from table_Pyz where ...... if @@error<>0 goto errif @@trancount>0 commit tran returnerr: if @@trancount>0 rollback tran
BEGIN TRAN BEGIN TRY DELETE FROM table1 where…… DETELE FROM table2 where…… COMMIT TRANSACTION END TRY BEGIN CATCH IF XACT_STATE()<>0 ROLLBACK TRANSACTION END CATCH如果你是SQL 2005 推荐使用这种方式
设置set xact_abort on即可。如: set xact_abort onbegin tran... commi tran
update....
delete ....
IF (@@ERROR <>0)
ROLLBACK TRANSACTION TranName
ELSE
COMMIT TRAN TranName
begin trandelete from table_Pqs where ......
if @@error<>0 goto errdelete from table_Pqh where ......
if @@error<>0 goto errdelete from table_Pyz where ......
if @@error<>0 goto errif @@trancount>0 commit tran
returnerr:
if @@trancount>0 rollback tran
BEGIN TRY
DELETE FROM table1 where……
DETELE FROM table2 where……
COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF XACT_STATE()<>0
ROLLBACK TRANSACTION
END CATCH如果你是SQL 2005 推荐使用这种方式
set xact_abort onbegin tran...
commi tran