Scripting Replication

SQL Replication

Replication

Scripting Replication

You can script commonly performed replication functions such as configuring publishing and distribution, and creating or deleting publications and subscriptions. After you configure or create a replication component, you can automate the creation of a script by using SQL Server Enterprise Manager.

The script contains the Transact-SQL system stored procedures necessary to implement the replication component. Composed primarily of a series of stored procedures, you can view, execute, and/or modify and run the script using SQL Query Analyzer or osql.

You can choose to script creation or deletion of one or a combination of the following:

  • Distributor properties

  • Publications and push subscriptions

  • Pull subscriptions

If you need to delete multiple push subscriptions or a mix of push and pull subscriptions, you can automate the process by creating a script to delete the publication. All subscriptions to the publication will be deleted with the publication. If you are deleting pull subscriptions, you can generate a script that deletes one or more pull subscriptions without deleting the publication.

Example

Northwind Traders decides to implement merge replication to distribute data to its remote sales force. A sales representative will be able to download all the data that pertains to the customers in their territory when they need it by using pull subscriptions. When working offline, they can update data and enter new customers and orders. When they reconnect and synchronize with the Publisher, their updates will be propagated to the Publisher and other Subscribers, and conflicts (if any) will be detected and resolved.

Because Northwind Traders has more than 50 sales representatives in different territories, it would be time-consuming to create the different subscriptions needed at each Subscriber. Instead, the replication administrator can set up the necessary merge publications (with static or dynamic partitions based on the sales representative or their territory), and then create a pull subscription, generate a script based on that pull subscription, and then run that script at multiple Subscribers to generate the necessary pull subscriptions.

To script replication