July 18, 2009 at 8:19 pm
Hi, I have a problem I'm hoping someone knows of a simple way to solve.
I have 4 tables, for simplicity lets call them A, B, C and D. The relationships are all one to many like this:
A has many B's which has many C's which has many D's. So to be clear, each D is associated with 1 C, which is associated to one B which is associated to 1 A.
I need to duplicate a record in B but assign it to a different record in A, and copy all of the C's and D's that were originally associated with that B, keeping the relationships intact. Essentially I need to copy all of the children from one record in A to another.
The only way I can think of doing this is to duplicate all of the records, get the primary keys as they are created, and painstakingly map them to the child records. There has to be an easier way!
I'm using Sql Server 2008 and C# 2008.
Thanks,
Eric
July 19, 2009 at 3:38 am
Have you tried temporarily disabling foreign key constraint checking?
July 19, 2009 at 3:50 am
Hi
There seems to be no simpler solution. Copy B(1) to B(2) with another A-key. Copy all C and D relations from B(1) to B(2).
However sounds quiet forward in my opinion. SQL Server is a RDBMS you cannot compare to .NET XML methods like XmlElement.Clone or XElement.ctor(other).
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply