define subscription

Description

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.

Syntax

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]

Parameters

sub_name

The name of the subscription, which must conform to the rules for naming identifiers. The subscription name must be unique for the replication definition, where applicable, and for the replicate data server and database.

for table_rep_def

Specifies the table replication definition the subscription is for.

for function_rep_def

Specifies the name of the function replication definition the subscription is for.

for publication pub_name

Specifies the publication the subscription is for.

for database replication definition db_repdef

Specifies the database replication definition the subscription is for.

with primary at data_server.database

Specifies the location of the primary data. If the primary database is part of a warm standby application, data_server.database is the name of the logical data server and database. Include this clause only for a subscription for a publication.

with replicate at data_server.database

Specifies the location of the replicate data. If the replicate database is part of a warm standby application, data_server.database is the name of the logical data server and database.

where

Sets criteria for the column or parameter values that are to be replicated via the subscription. If you omit the where clause, all rows or parameters are replicated.

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.

column_name

A column name from the primary table, for a subscription to a table replication definition.

@param_name

A parameter name from a replicated stored procedure, for a subscription to a function replication definition.

value

A value for a specified column or parameter. See “Datatypes” for entry formats for values for different datatypes.

subscribe to truncate table

For a subscription to a table replication definition or to a publication, enables replication of the truncate table command to the subscribing replicate database.

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.

for new articles

Refreshes an existing subscription. Instructs Replication Server to check the subscription against the publication and then to create subscriptions against unsubscribed articles.

use dump marker

Tells Replication Server to apply transactions to a replicate database. use dump marker activates and validates the database subscription automatically. Without this option, users must activate and validate the database subscription manually.

NoteUse dump marker one at a time as you cannot define multiple database subscriptions with dump marker. You also need to place a dump database command between each subscription command.

Examples

Example 1

Creates a subscription named titles_sub. It specifies that rows from the titles table with columns of the type “business” are to be replicated in the titles table in the pubs2 database of the data server named SYDNEY_DS:

define subscription titles_sub
  for titles_rep
    with replicate at SYDNEY_DS.pubs2
    where type = 'business'

Example 2

Creates a subscription named titles_sub that includes rows from the titles table with prices that are greater than or equal to $10.00:

define subscription titles_sub
  for titles_rep
    with replicate at SYDNEY_DS.pubs2
    where price >= $10.00

Example 3

Creates a subscription named myproc_sub for the function replication definition myproc_rep:

define subscription myproc_sub
  for myproc_rep
    with replicate at SYDNEY_DS.pubs2

Example 4

Creates a subscription named pubs2_sub for the publication pubs2_pub:

define subscription pubs2_sub
  for publication pubs2_pub
    with primary at TOKYO_DS.pubs2
    with replicate at SYDNEY_DS.pubs2

Example 5

Creates a subscription pubs2_sub for the database replication definition pubs2_rep:

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.

Usage


Subscribing to publications


Subscribing to database replication definitions


Replicating truncate table


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

In addition to the permissions listed below, make sure these requirements are met before you execute this command.


Creating subscriptions using define subscription


Alternative command to create subscriptions

Permissions

To execute define subscription, you must have the following login names and permissions:

See also

alter applied function replication definition, alter request function replication definition, activate subscription, check subscription, create article, create function replication definition, create publication, create applied function replication definition, create request function replication definition, create subscription, drop subscription, sysadmin apply_truncate_table, validate subscription