Adds a subscription to the Replication Server system tables, but does not materialize or activate the subscription. The subscription may be for a database replication definition, a table replication definition, a function replication definition, or for a publication. This command begins the process of bulk subscription materialization, or the process of refreshing a publication subscription.
define subscription sub_name for {table_rep_def | function_rep_def | publication pub_name | database replication definition db_repdef with primary at data_server.database} | with replicate at data_server.database [where {column_name | @param_name} {< | > | >= | <= | = | &} value [and {column_name | @param_name} {< | > | >= | <= | = | &} value]...] [subscribe to truncate table] [for new articles] [use dump marker]
You can include a where clause in a subscription for a table or function replication definition. You cannot include a where clause in a publication subscription.
A where clause is composed of one or more simple comparisons, in which a searchable column or searchable parameter from the replication definition is compared to a literal value using one of these relational operators: <, >, <=, >=, =, or &. (The & operator is supported only for rs_address columns or parameters.) You can join comparisons with the keyword and.
Column or parameter names used in the expression must be included in the searchable columns list of the table replication definition or in the searchable parameters list of the function replication definition.
Java columns cannot be evaluated in subscription expressions. Thus, you cannot include a Java column of type rawobject or rawobject in row in a where clause.
You must set this option the same as it is set for any existing subscriptions that replicate data into the same replicate table. Otherwise, the new subscription will be rejected.
define subscription titles_sub for titles_rep with replicate at SYDNEY_DS.pubs2 where type = 'business'
define subscription titles_sub for titles_rep with replicate at SYDNEY_DS.pubs2 where price >= $10.00
define subscription myproc_sub for myproc_rep with replicate at SYDNEY_DS.pubs2
define subscription pubs2_sub for publication pubs2_pub with primary at TOKYO_DS.pubs2 with replicate at SYDNEY_DS.pubs2
define subscription pubs2_sub for database replication definition pubs2_rep with primary at NEWYORK_DS.pubs2 with replicate at TOKYO_DS.pubs2 subscribe to truncate table use dump marker
Refer to the Replication Server Design Guide for examples of creating subscriptions for a complete replication system.
Use define subscription to create a subscription manually using bulk materialization. With bulk materialization, subscription creation and materialization is performed in discrete steps so that you can load the initial data from media rather than sending it from the primary database through the WAN.
If you have added any new articles to a publication with an existing subscription, you must refresh the publication subscription in order to create new subscriptions for these articles.
Activate the subscription using activate subscription and validate the subscription using validate subscription.
Although you can create multiple replication definitions for the same primary table, you cannot subscribe to more than one replication definition for the same replicate table. However, you can subscribe to the same replication definition more than once.
Subscribing to Publications
You can create a subscription for a valid publication to begin replication to a replicate database. All forms of subscription materialization are supported.
Use define subscription to create new article subscriptions in the publication subscription. Then use activate subscription, manually load the subscription data for the new article subscriptions, and use validate subscription to validate the publication subscription.
When you create a publication subscription, Replication Server creates a separate underlying subscription for each article that the publication contains. Each article subscription uses the name of the parent publication subscription.
When you activate and validate a publication subscription, all of its article subscriptions are activated and validated at the same time.
A subscription to a publication cannot include a where clause. Instead, you can customize replication to replicate sites by including one or more where clauses in each article the publication contains.
Subscribing to Database Replication Definitions
When you create a database subscription, you cannot use the where clause to limit data subscription. All data is subscribed.
With database subscriptions, you can use only the no materialization or bulk materialization methods. Use define subscription to use dump and load or other bulk materialization method. Use create subscription to use the no materialization method.
You cannot subscribe to more than one database replication definition from the same origin.
Replicating Truncate Table
When you create the first subscription for a table, you can either include or not include the subscribe to truncate table option. Each subsequent subscription that copies information into the same table must follow the example of the first subscription. Otherwise, it will be rejected when you try to create it.
You can view or change the current “subscribe to truncate table” status of a particular replicate table by executing sysadmin apply_truncate_status.
Working with the rs_address Datatype
See create subscription for information about working with columns or parameters that use the rs_address datatype.
Requirements for Executing define subscription
A replication definition exists for the primary table you are replicating, and the table is marked for replication with sp_setreptable.
Tables referenced in the replication definition exist in both the primary and the replicate database. Each table has the columns and datatypes defined in the replication definition.
This table is also visible to the user creating the subscription and the user maintaining it. The easiest way to achieve this is to have the Database Owner create the table.
A replication definition exists for the stored procedure you are replicating, and the stored procedure is marked for replication with sp_setrepproc.
Stored procedures referenced in the function replication definition exist in both the primary and replicate database. Each table has the parameters and datatypes defined in the function replication definition.
Creating Subscriptions Using Define Subscription
For a subscription to a table replication definition, enter define subscription at the Replication Server that manages the database where the replicate data is to be stored.
For a subscription to a function replication definition, enter define subscription at the Replication Server that manages the database where the destination stored procedure is to be executed via applied function delivery.
For a subscription to a publication, enter define subscription at the Replication Server that manages the database where the replicate data is to be stored or where destination stored procedures are to be executed.
A table subscription maintains a replicate copy of a table, or selected rows from a table, in a database. Changes made to the primary version are also applied to the copy.
A function subscription replicates user-defined function invocations associated with a function replication definition. A replicated function typically includes parameters and modifies data, but it needs not involve replicated data.
A publication subscription involves underlying subscriptions for the articles the publication contains, which replicate table or user-defined function invocations depending on the replication definitions in the article.
See the Replication Server Administration Guide Volume 1 for more information about subscriptions and the role they play in replication.
Alternative Command to create subscriptions
The same login name and password at the replicate Replication Server, primary Replication Server, and primary database.
“create object” or “sa” permission at the replicate Replication Server where you enter this command.
“create object”, “primary subscribe”, or “sa” permission at the primary Replication Server.