Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Replication not replicating Foreign Keys

I am replicating several tables to a database on the same server as the source database.

Those tables have several foreign keys between them. When I look at the replicated tables, they do not have the foreign keys on them.

So, here are my questions:

  1. Should replication be copying these foreign keys by default?
  2. If not, how can I get them to replicate?
  3. If so, what would cause them to not replicate?

NOTE: My source database has TableA and TableB. TableA has a primary key of AId. TableB has a foreign key on that column. And I am doing a transactional replication of both TableA and TableB.

like image 737
Vaccano Avatar asked Sep 26 '11 18:09

Vaccano


1 Answers

OK, I came across something, but it would depend on what type of replication you are using.

I am using transactional replcation. Find the publication you are using here,

(Management Studio) Replication -> Local Publications -> (Publication)

Right click the publication and select properties, then under articles right click 'Tables' and select the option 'Set Properties of All Table Articles'.

In there the first item is 'Copy foreign key constraints'.

Haven't tried it, but I expect it to work.

You can apply these settings per table too if you right click a single table and select the option 'Set Properties of This Table Article'.

like image 194
peter Avatar answered Nov 03 '22 23:11

peter