Quick Hits: Microsoft SQL and Transactions

The following is a quick post on a DBMS system named SQL Server. I hope you find this post helpful in better understanding SQL Server and Transactions, as this was a topic that originally confused me.

SQL Server uses Transact-SQL to facilitate Distributed Transactions. The distributed transactions started in Transact-SQL have a relative simple structure. A Transact-SQL script or application connection execute a Transact-SQL statement that begins the distributed transaction. The instance of SQL Server Database Engine executing the statement becomes the controlling server in the transaction. The script or application then executes either distributed queries against linked servers or remote stored procedures against remote servers. As distributed queries and remote procedure calls are made, the controlling server automatically calls Microsoft Distributed Transaction  Coordinator (MS DTC) to enlist the linked and remote servers in the distributed transaction. When the script or application issues either a COMMIT or ROLLBACK statement, the controlling SQL Server calls MS DTC to manage the two-phase commit process or to notify the linked and remote servers to roll back their transaction.

The Transact-SQL statements controlling the distributed transactions are few because most of the work is done internally by the SQL Server Database Engine and MS DTC.

You can start distributed transactions in Transact-SQL using the BEGIN DISTRIBUTED TRANSACTION statement. You can also execute a distributed query against a linked server. The instance of the Database Engine you have connected to calls MS DTC to manage the distributed transaction with the linked server. You can also call remote stored procedures on a remote instance of the Database Engine as part of the distributed transaction.