When the Log Reader Agent encounters an INSERT, UPDATE, or DELETE statement marked for replication in the transaction log of a publication database, it usually reconstructs a single row Transact-SQL statement from the recorded data changes. The Distribution Agent then sends that reconstructed Transact-SQL statement to each Subscriber and applies the statement to the destination table in each destination database. This is the default data replication mechanism used by Microsoft® SQL Server™ when there are one or more heterogeneous Subscribers.
If all Subscribers are SQL Server databases, SQL Server can override the INSERT, UPDATE, and DELETE statements from the transaction log with custom stored procedures at each Subscriber. For each published table, there are three ways you can handle each type of statement (INSERT, UPDATE, or DELETE) detected by the Log Reader Agent. You can:
To implement custom, stored procedure–based replication for a published table, stored procedures must be created by either replication or the user. These custom stored procedures expect to receive and process these parameters:
c1, c2, c3,... cn
c1, c2, c3,... cn, pkc1, pkc2,... pkcn
Note No attempt is made to determine which columns were changed.
pkc1, pkc2,... pkcn
c1, c2, c3,... cn, pkc1, pkc2,... pkcn, bitmask
old-c1, old-c2, old-c3,... old-cn, c1, c2, c3,... cn,
old-c1, old-c2, old-c3,... old-cn
If you would like your INSERT, UPDATE, or DELETE stored procedure to return an error when a failure status is encountered, you must add a RAISERROR statement so that the distributor will catch the failure status coming back. If severity is greater than 12, it stops the distribution process to that subscriber. If this procedure definition is distributed as part of the article schema definition file, it will be sent using ODBC. In this case, only single quotes (') may be used to define the RAISERROR message string, because use of double quotes (") will generate an error.
Indicate your choice when you specify article properties in the Create Publication Wizard. You can also make this choice on the Properties dialog box for the article.
To replace statements with custom stored procedures in an article