Setup Through Scripts
So far, we have seen how to set up replication using wizards, which is not too difficult, but is time-consuming. Now, imagine that we have to configure the same setup in multiple environments; for instance, on development and quality assurance servers. Clicking through the wizards is lengthy and tedious. Fortunately, there is a better way. After we create publications and subscriptions, we can script them. Then we can edit the scripts slightly to ensure that proper servers are affected and run the scripts on a different set of publishers and subscribers.
To script replication stored procedures, we navigate to the replication/publications folder on the publisher. We right-click the desired publication and choose Generate SQL script. Doing this opens the dialog box shown in the next figure.
We have a number of options for scripting the publication. If we navigate to the replication/subscriptions folder on the subscriber, we can script pull subscriptions the same way. If we choose Tools, Replication, Generate SQL Script on the distribution server, we get a slightly different dialog box that allows us to generate replication scripts as well.