Home > Archive > MS SQL Server > January 2006 > Modeling question: Entity containment in more than one parent enitities









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Modeling question: Entity containment in more than one parent enitities
Christoph Wienands

2006-01-19, 11:23 am

Hey guys,

I'm currently trying to model the following class hierarchy:

Class A and class B have both a collection of class C objects. This relation
is supposed to be containment, which means if I delete an object of type A
all the referenced Cs are deleted as well. Same accounts for class B.

For the database I have a table A, B and C. Now I'm stuck with creating the
appropriate relations and foreign keys. I see two possibilities:

1) Table C has an ID as primary key. I have two m:n tables between A-C and
B-C. Problem is, entries in C won't get deleted upon deletion of A or B
entries. Furthermore, on C entry could be contained in both A and B
(alright, my class model doesn't prevent that either). I could create a
trigger that will take care of the deleting but I just don't like the
primary key in table C and the m:n table because C is contained in A and B.

A --> m:n <-- C --> m:n <-- B

2) Table C has a column ForeignID (same type as ID columns in A and B).
Relations go from A-C and from B-C with A's and B's ID as primary key and
C's ForeignID column as foreign key. This way the relation with cascading
delete will make sure the C entries get deleted. However, this approach
doesn't look "clean" to me because C's ForeignID column doesn't always refer
to the same table as foreign key.

A --> C <-- B

What's your opinion on that? Any other possibilities

Thanks, Christoph


Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com