Copy codeThe Code is as follows:
-- Begin distributed transaction [transactionname]
-- Mark a TSQL Distributed Transaction managed by the Distributed Transaction Processing Coordinator MSDTC.
-- Server a is the master SERVER. When the connection sends a subsequent commit transaction or
-- Rollback transaction statement, the master server requests MSDTC to manage between involved servers
-- Completion of distributed transactions
-- SQLSERVER uses the linked server or remote server as the platform for distributed transaction processing.
-- Remote Stored Procedure Call and Distributed Query
-- When using distributed transactions for A remote stored procedure call and A Distributed Query
-- Issue begin distributed transaction, the connection calls the stored procedure on SERVER B
-- Another stored procedure on server c, and the stored procedure on server c executes
-- Distributed Query: Four SQLSERVER servers enter the distributed transaction. server a is the creator of the transaction.
-- And Control Server
-- Create a distributed transaction and delete a record in both the local and remote databases.
-- The Instance name is RemoteServer. The local and remote databases submit or roll back the transaction at the same time.
-- Note that four naming rules are used for executing distributed queries or calling stored procedures.
-- Prerequisite: the MSDTC Service on the local machine and the MSDTC Service on the remote machine must be enabled.
-- The local machine and remote machine can ping each other
-- Database ports can be telnet to each other
-- Create a linked server to a remote machine WIN7U-20130414Z
USE [GPOSDB]
GO
SELECT * FROM [SystemPara] WHERE [Name] = 'hdtport'
SELECT * FROM [WIN7U-20130414Z]. [GPOSDB]. dbo. [SystemPara] WHERE [Name] = 'hdtport'
USE [GPOSDB]
GO
BEGIN DISTRIBUTED TRANSACTION
-- Delete a record from the local database
Delete from [JOE]. [GPOSDB]. [DBO]. [SystemPara]
WHERE [Name] = 'hdport'
-- Delete a record from the remote database
Delete from [GPOSDB]. [dbo]. [SystemPara]
WHERE [Name] = 'hdport'
COMMIT TRAN
GO
-- I tried it because the two-way SQL server access adopts the chained access (Login server access ),
-- In this case, you only need to set the statement for accessing the database of the other Party:
-- Select * from linkedServerA. dbo. table1
-- Modify:
-- Select * from dbo. table1.
-- Mark it for future resolution.