You can also use applied functions to replicate stored procedure invocations to remote sites with replicate data. If you use applied functions to replicate primary data, you can:
Reduce network traffic over the WAN
Increase throughput and decrease latency because applied functions execute more rapidly
Enable a more modular system design
In the following example, a client application at the primary (Tokyo) site executes a user stored procedure, upd_publishers_pubs2, which makes changes to the publishers table in the primary database. Execution of upd_publishers_pubs2 invokes function replication, which causes the corresponding stored procedure, also named upd_publishers_pubs2, to execute on the replicate data server.
To create an applied function for an application that implements the basic primary copy model, you need to:
Create the user stored procedure in the primary database.
Mark the user stored procedure for replicated function delivery using sp_setrepproc.
Grant the appropriate procedure permissions to the appropriate user.
At the primary Replication Server, create the function replication definition for the stored procedure with parameters and datatypes that match those of the stored procedure. You can specify only the parameters you want to replicate.
Create a stored procedure in the replicate database with the same parameters (or a subset of those parameters) and datatypes as those created in the primary database. Grant appropriate permissions to the procedure to the maintenance user.
Create a subscription to the function replication definition in the replicate Replication Server.
Figure 3-2: Basic primary copy model using applied functions