CREATE PROCEDURE deleteAccountAll @id int AS SET XACT_abort ON BEGIN DISTRIBUTED TRAN delete from AccountCapital where accountid = @id delete from logininfo where username = @id delete from CapitalRecord where accountid = @id delete from [Trade]..[order] where accountid = @id delete from account where id = @id if @@error<>0 rollback tran else commit tran GO
其中order表与其他几个表不在同一个数据库实例,若想实现事务操作,具体要注意两点:
1.打开MSDTC服务,即 set XACT_abort on ,若本机没有启动,则运行 net start msdtc