We help IT Professionals succeed at work.

Foreign key and transactional replication

Mehram
Mehram asked
on
Medium Priority
632 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.
Comment
Watch Question

SQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
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?
Raja Jegan RSQL Server DBA & Architect, EE Solution Guide
CERTIFIED EXPERT
Awarded 2009
Distinguished Expert 2019

Commented:
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.

Author

Commented:
Thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.