?
Solved

Foreign key and transactional replication

Posted on 2009-02-16
4
Medium Priority
?
600 Views
Last Modified: 2012-08-13
MS SQL Server 2005

Publisher:   sdmsrv.siddiqsons
Subscriber: dcsrv.prod_dcity

Setup tables such as colour, customer, product etc are maintained in sdmsrv.siddiqsons and prod_dcity cannot add/edit these tables.
These tables primary keys are foreign keys to many many tables.

We are replicating these tables (transactional replication) to prod_dcity.
Sometimes rather quite oftern we had to regenerate snapshot or re-activate the replication. Then, sql server method is to delete rows (or drop the table completely) in prod_dcity. BECAUSE OF THIS BEHAVIOUR , WE GET FOREIGN KEY ERROR.

RIGHT NOW, WE HAVE REMOVED ALL FOREIGN KEYS IN PROD_DCITY RELATED WITH THE SETUP TABLES BUT THIS SEEMS TO BE VERY BAD.

HOW TO OVERCOME THIS BEHAVIOUR OF SQL SERVER.
0
Comment
Question by:Mehram
  • 2
  • 2
4 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 2000 total points
ID: 23657755
One of the Key consideration for Replication in SQL Server is that :

* Remove referential integrity constraints from the subscriber database when you use automatic synchronization to keep replication errors and problems to a minimum.
* Referential integrity isnt necessary on the subscriber because it has already been performed on the publishing database. You are assured that the data relationships have already been verified before they are sent to the subscriber.

Since Replication is itself considered following these considerations, you have no other option except removing Foreign Keys in your table.
0
 

Author Comment

by:Mehram
ID: 23688893
He rrjegan17

Though the question is accepted,

In the foreign key, there is an option "Enforce for replication" . What does that do.

Our behaviour,

We have definite sets of colours and it is strictly maintained in main server and users of other servers are not allowed to create new colour. Hence we only replicate colour and off-course then we have the above problem.

Please tell, are we doing things in the right way?
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 23691289
Ok.. Enforce For Replication -- Indicates whether to enforce the constraint when a replication agent performs an insert, update, or delete on this table.

<< We have definite sets of colours and it is strictly maintained in main server and users of other servers are not allowed to create new colour. Hence we only replicate colour and off-course then we have the above problem.  >>

Then we have to replicate colours table first and after that do the child tables. But what happens if that order is changed.. You would get a violation right and that is what happening to you.

Ideally we have it turned on.. But we need to turn it off in some cases when records we are going to merge violates the Foreign key. A more detailed explanation is provided in the link below for you reference:

http://www.ssw.com.au/SSW/kb/KB.aspx?KBID=Q155706
http://support.microsoft.com/kb/308266

Hope the above two provides more insight and why I asked you to turn if to off.
0
 

Author Comment

by:Mehram
ID: 23698475
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question