How do I replicate tables from different schemas?
Set the destination owner in the publication to be the schema name in the subscriber.
Here's the scenario, you have two databases. The first database is the publisher. The second database is the subscriber. You want to replicate tables from the publisher to the subscriber. You do not want to give the subscriber full rights to the replicated tables.
So you want to replicate the tables to a special schema on the subscriber. Setting up a schema will give you the power to control what the subscriber can do with the tables.
I am not a DBA, but I play one at work. I welcome your feedback.
Open SQL Server 2008. Create two databases. Name the first PublisherDatabase and the second SubscriberDatabase.
Inside the PublisherDatabase, run the following script to create a table.
Let's insert a person.
The goal is to replicate this table to the SubscriberDatabase, but the user of the SubscriberDatabase should only have select rights on the table. They cannot insert, update, or delete records from the table. Creating a schema and replicating the table to this schema is a good way to limit rights.
Let's create the schema on the subscriber database.
We now have a schema named "repl" and our user has limited rights in the schema.
Let's set up replication.
You might get an error that the SQL Agent is not started. Just right-click on the SQL Server Agent and start it.
Now we need to set up a subscription.
You would think the Person table would be in the SubscriberDatabase right? Well, we have one more step to go.
You can click the monitor button to watch the process.
Eventually you will replicate the table to the SubscriberDatabase.
Congratulations, you have now replicated a table from one schema to a different schema.
Don't forget to use the schema name with querying the table.