SQL Server Distributed transaction usages _mssql

Source: Internet
Author: User
Tags commit

Copy Code code as follows:

--begin distributed TRANSACTION [Transactionname]
--Flags a TSQL distributed transaction starting with the Distributed Transaction Coordinator MSDTC Management
--server a server as the primary control server. When the connection issues a subsequent commit transaction or
--rollback TRANSACTION statement, the master server requests MSDTC to manage between the servers involved
--Completion of distributed transactions

--sqlserver uses a linked server or remote server as a platform for distributed transaction processing, providing
--Remote stored procedure calls and distributed queries


-When using a distributed transaction for a remote stored procedure call and a distributed query, in server A
--A BEGIN distributed TRANSACTION is issued that invokes the stored procedure on server B
--and another stored procedure on Server C, and the stored procedure on server C executes a
--distributed queries, four SQL Server servers into a distributed transaction, Server A is the creator of the transaction
--and control server

--Create a distributed transaction and delete a record at the local and remote databases, where remote SQL Server
-the instance name is RemoteServer. Both local and remote databases commit or roll back the transaction at the same time.
--note that when executing a distributed query or invoking a stored procedure, a 4-part name is used to qualify the rule

--Prerequisite: The MSDTC of this machine and the MSDTC service of the remote machine to open
--This machine and the remote machine can ping each other
--Database ports can 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]= ' Hdtport '

--Deletes a record from the remote database
DELETE from [Gposdb]. [dbo]. [Systempara]
WHERE [name]= ' Hdtport '

COMMIT TRAN
Go


--a personal attempt was made because of the chained access (linkedserver) in bidirectional SQL Server access,
--When you encounter this situation, you only need to use the statement that originally accessed the other database:
--select * from LinkedServerA.dbo.table1
--Modified to:
--select * from Dbo.table1.
--marked down for later resolution.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.