Replication

Immediate Updating Components

Immediate updating is supported using:

Triggers

An update trigger at the Publisher updates the MSrepl_tran_version column for the updated rows when needed.

Triggers at the Subscriber capture transactions and submit them to the Publisher using a remote stored procedure call within a 2PC that is controlled by MS DTC. The triggers are created using the NOT FOR REPLICATION parameter of the CREATE TRIGGER statement so that changes applied by the Distribution Agent do not themselves cause the trigger to fire. The logic of the INSERT, UPDATE, and DELETE triggers is:

Stored Procedures

Stored procedures at the Publisher apply transactions only if they do not conflict with changes made at the Publisher after the Subscriber last received its copy of the changes. If a conflict is detected, the transaction is rejected and rolled back at both sites. INSERT, UPDATE, and DELETE procedures are created for each article. The logic of the immediate updating subscription stored procedure at the Publisher is:

Note  A transaction that affects multiple rows must have all rows reflected at both sites to succeed.

Microsoft Distributed Transaction Coordinator

Microsoft Distributed Transaction Coordinator (MS DTC) manages the two-phase commit operation between a Subscriber and Publisher inside a Microsoft® SQL Server™ 2000 remote stored procedure call using the BEGIN DISTRIBUTED TRANSACTION statement in Transact-SQL.

Conflict Detection

The Publisher stored procedure uses the uniqueidentifier column to detect whether a row has changed after it was replicated to the Subscriber. When the Subscriber requests an immediate-update transaction, it passes the uniqueidentifier value (generated at the Subscriber) to the Publisher, along with all other columns in the row. Within the Publisher's stored procedure, this value is compared to the current uniqueidentifier value for the row in question. If the values are the same, the row has not been modified after it was replicated to the Subscriber, and so the transaction is accepted. If a conflict is detected, the transaction is rejected, and the application should treat it like any transaction rollback. This usually means that the Subscriber needs to synchronize with the latest data changes at the Publisher before attempting to update the same data locally.

Loopback Detection

If a transaction is applied successfully to a Subscriber and Publisher, it is unnecessary to propagate the change back to the originating Subscriber using the standard asynchronous transaction replication mechanisms. SQL Server 2000 replication has a loopback detection mechanism to handle this situation.

The information used to perform loopback detection is stored on a transaction-by-transaction basis. Consequently, tables that reside in different databases at the Subscriber with immediate updating subscriptions or tables that reside in different databases across Subscribers with immediate updating subscriptions should not be updated in the same transaction.

Warning  Using the same transaction to update tables that reside in different databases at the Subscriber or to update tables that reside in different databases across Subscribers that have immediate updating subscriptions will delete the information necessary to control loopback detection and may cause replication to fail. Loopback detection is tracked at the transaction level. If the transaction involves more than one subscription database, SQL Server will attempt to mark the transaction with the Subscriber server name and database name multiple times. The last entry will overwrite all previous entries.