当前位置:首页 > 数据库 > Sqlserver

SQL Server 跨数据库事务

TRY       BEGIN TRAN         INSERT INTO DB1.dbo.Log                 ( Type, Message, Stack, Created )         VALUES  ( 0, -- Type - int                   N‘Message‘, -- Message - nvarchar(100)                   N‘Stack‘, -- Stack - nvarchar(max)                   ‘2010-03-12 05:43:17‘  -- Created - datetime                   )                          --  RAISERROR (‘插入第一个库后失败.‘, -- Message text.                         --16, -- Severity.                         --1 -- State.                      --  );                         INSERT INTO DB2.dbo.Agent                 ( Name ,                   Mobile ,                   Password ,                   LocationID ,                   Address ,                   Status ,                   CreateTime                 )         VALUES  ( N‘Name‘ , -- Name - nvarchar(50)                   ‘Mobile‘ , -- Mobile - varchar(16)                   ‘Password‘ , -- Password - varchar(64)                   0 , -- LocationID - int                   N‘Address‘ , -- Address - nvarchar(256)                   0 , -- Status - int                   ‘2015-05-22 05:43:48‘  -- CreateTime - datetime                 )                                    --RAISERROR (‘插入第二个库后失败.‘, -- Message text.         --                16, -- Severity.         --                1 -- State.         --               );                                 EXEC TestDB.dbo.SP_T1   --DB3存储过程                          RAISERROR (‘插入存储过程后失败.‘, -- Message text.                     16, -- Severity.                     1 -- State.                    );                    COMMIT TRAN END TRY   BEGIN CATCH     IF @@TRANCOUNT > 0---------------判断有没有事务         BEGIN             PRINT ERROR_MESSAGE()             ROLLBACK TRAN----------回滚事务         END  END CATCH    



来自为知笔记(Wiz)



SQL Server 跨数据库事务

标签:

本文系统来源:http://www.cnblogs.com/gossip/p/4522193.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐