Learn how to create replication objects and execute commands to implement a request function.
Applied and request functions are very similar. The difference is that the maintenance user executes the applied function at the replicate site, and the same user who executes the stored procedure at the primary database executes the request function at the replicate site.
create proc update_pubs @pub_id char(4), @pub_name varchar(40) as update publishers set pub_name = @pub_name where pub_id = @pub_id
Do not mark this stored procedure as replicated; however, if this database is also part of a warm standby application, then mark the stored procedure in the active database as replicated if you want to replicate stored procedures to the standby database.
grant execute on update_pubs to pubs_user
create proc update_pubs_request @pub_id char(4), @pub_name varchar(40) as print "Transaction accepted."
sp_setrepproc update_pubs_request, 'function'
grant execute on update_pubs_request to pubs_user
create request function replication definition update_pubs_request_rep with primary at TOKYO_DS.pubs2 with primary function named update_pubs_request with replicate function named update_pubs (@pub_id char(4), @pub_name varchar(40)), @state char (2)) searchable parameters ( @state)
The request function replication definition must use the same parameter names and datatypes as the stored procedure in the replicate database. You have the option to include only the parameters you want to replicate.
See Replication Server Reference Manual > Replication Server Commands > create request function replication definition.
If you are not using a default function string or wish to customize the function’s invocation, you need to create a function string for the user-defined function.
create subscription pubs_sub for update_pubs_request_rep with replicate at SYDNEY_DS.pubs2 where @state = ‘CA’ without materialization
If you specified searchable parameters in the function replication definition, you can subscribe to function invocations based on the value of the function’s parameters. In this example, the subscription only receives rows if the value of the @state parameter is equal to “CA”.
See Replication Server Reference Manual > Replication Server Commands > create subscription.
See Replication Server Reference Manual > RSSD Stored Procedures for information about stored procedures, such as rs_helpfunc, that you can use to query the RSSD for information about the replication system.