create replication definition

Description

Creates a replication definition for a table that is to be replicated.

Syntax

create replication definition replication_definition
with primary at data_server.database
[with all tables named [table_owner.] 'table_name' |
[with primary table named [table_owner.]'table_name']
with replicate table named
              [table_owner.]'table_name']]
(column_name [as replicate_column_name]
              [datatype [null | not null] 
              [map to published_datatype]] 
[, column_name [as replicate_column_name]
              [datatype [null | not null] computed]
              [map to published_datatype ]]...)
primary key (column_name [, column_name]...)
[searchable columns (column_name 
              [, column_name]...)]
[send standby [{all | replication definition}
              columns]]
[replicate {minimal | all} columns]
[replicate_if_changed
              (column_name [, column_name]...)]
[always_replicate (column_name [, column_name]...)]

Parameters

replication_definition

The replication definition, which must conform to the rules for identifiers. The replication definition name is assumed to be the name of both the primary and replicate tables, unless you specify the table names.

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.

with all tables named

Specifies the table name at both the primary and replicate databases. table_name is a character string of up to 200 characters. table_owner is optional, and represents the table owner. Data server operations may fail if the actual table owners do not correspond to what you specify in the replication definition.

with primary table named

Specifies the table name at the primary database. table_name is a character string of up to 200 characters. table_owner is optional and represents the table owner. Data server operations may fail if the actual table owners do not correspond to what you specify in the replication definition.

If you specify the primary table name but do not also specify the replicate table name, the replication definition name is assumed to be the name of the replicate table.

with replicate table named

Specifies the name of the table at the replicate database. table_name is a character string of up to 200 characters. table_owner is optional and represents the table owner. Data server operations may fail if the actual table owners do not correspond to what you specify in the replication definition.

If you specify the replicate table name but do not also specify the primary table name, the replication definition name is assumed to be the name of the primary table.

column_name

A column name from the primary table. You cannot use a column name more than once in each clause.

Each column and datatypes must be enclosed in parentheses ( ).

as replicate_column_name

Specifies a column name in a replicate table into which data from the primary column will be copied. Use this clause when the source and destination columns have different names.

datatype

The datatype of the column in the primary table. See “Datatypes” for a list of the datatypes and syntax.

Use as declared_datatype if you are specifying a column-level datatype translation. A declared datatype must be a native Replication Server datatype or a datatype definition for the primary datatype.

For different replication definitions created against the same table, the column datatypes must be the same, however the published datatypes may be different. See the Replication Server Administration Guide Volume 1 for more information.

Specifying the datatype is optional if a replication definition created against the same table already has this column.

null or not null

Applies only to text, unitext, image, or rawobject columns. Specifies whether a null value is allowed in the replicate table. The default is not null, meaning that the replicate table does not accept null values.

The null status for each text, unitext, image, and rawobject column must match for all replication definitions for the same primary table, and must match the settings in the actual tables. Specifying the null status is optional if an existing replication definition of the same primary table has text, unitext, image, and rawobject columns.

You cannot change this setting for a column once it is included in a replication definition for the table. To change the value, you must drop and re-create all replication definitions that include the column.

map to published_datatype

Specifies the datatype of a column after a column-level datatype translation, but before any class-level translation and before presentation to the replicate database.

primary key column_name

Specifies the columns that form the primary key for the table. You cannot use a column name more than once in each clause.

You cannot include text, unitext, image, rawobject, rawobject in row, or rs_address columns as part of the primary key.

searchable columns column_name

Specifies the columns that can be used in where clauses of create subscription, define subscription, or create article. You cannot use a column name more than once in each clause.

You cannot specify text, unitext, image, rawobject, rawobject in row or encrypted columns as searchable columns.

send standby

Specifies how to use the replication definition in replicating into a standby database in a warm standby application. See “Replication definitions and warm standby applications” for details on using this clause and its options.

replicate minimal columns or replicate all columns

Sends all replication definition columns for every transaction or only those needed to perform update or delete operations at replicate databases. The default is to replicate all columns.

replicate_if_changed

Replicate text, unitext, image, or rawobject columns only when their column data changes.

always_replicate

Always replicate text, unitext, image, and rawobject columns.

Examples

Example 1

Creates a replication definition named authors_rep for the authors table. The primary copy of the authors table is in the pubs2 database in the LDS data server. All copies of the table are also named authors. Only the minimum number of columns will be replicated for delete and update operations:

create replication definition authors_rep
  with primary at LDS.pubs2
  with all tables named 'authors'
    (au_id varchar(11), au_lname varchar(40),
     au_fname varchar(20), phone char(12),
     address varchar(12), city varchar(20),
     state char(2), country varchar(12), postalcode
     char(10))
  primary key (au_id)
  searchable columns (au_id, au_lname)
  replicate minimal columns

Example 2

Creates a replication definition called blurbs_rep for the blurbs table owned by “emily” in the pubs2 database. Data in the copy column, which uses the text datatype and accepts null values, will be replicated when the column data changes:

create replication definition blurbs_rep
  with primary at TOKYO_DS.pubs2
  with all tables named emily.'blurbs'
    (au_id char(12), copy text null)
  primary key (au_id)
  replicate_if_changed (copy)

Example 3

Where at least one replication definition already exists for the primary table publishers in the pubs2 database, this command creates an additional replication definition called pubs_copy_rep. This replication definition can be subscribed to by replicate tables that are named pubs_copy and for which “joe” is the owner. Subscriptions may fail for replicate tables that are also named pubs_copy but for which “joe” is not the owner:

create replication definition pubs_copy_rep
  with primary at TOKYO_DS.pubs2
  with primary table named 'publishers'
  with replicate table named joe.'pubs_copy'
    (pub_id, pub_name as pub_name_set)
  primary key (pub_id)

Data for the pub_name column in the primary table will replicate into the pub_name_set column in the replicate table, which must share the same datatype. You do not need to specify the datatype for a column in an existing replication definition. In this example, the city and state columns from the primary table are not required for the replicate table pubs_copy, and are thus excluded from this replication definition.

Example 4

Creates a replication definition that replicates all modified columns of the authors table to the standby database. This definition also replicates to the MSA, however, only the modified values of au_id and au_lname columns are replicated. au_id is the key used to update and delete from the authors table:

create replication definition authors_rep
  with primary at LDS.pubs2
  with all tables named 'authors'
     (au_id varchar(11), au_lname varchar(40))
  primary key (au_id)
  send standby
  replicate minimal columns

Usage


Replication status


Creating multiple replication definitions


Functions and function strings


Specifying columns and datatypes


Specifying columns and datatypes for column-level translations


Using the replicate minimal columns option


Replicating text, unitext, image, or rawobject datatypes


Replication definitions and warm standby applications


Altering replication definitions


Replicating stored procedures


Replicating computed columns

For more information on replicating computed columns, see Replication Server Administration Guide Volume 1.

Permissions

create replication definition requires “create object” permission.

See also

alter function string, alter replication definition, configure logical connection, create connection, create function replication definition, create function string, create subscription, drop replication definition, set autocorrection, sp_setrepcol, sp_setreptable