1

How to avoid multiple tables tables to relations M: M?

see the next model

enter image description here

As can be seen by each multiple choice I create a couple of tables, that I have always worked well, but now I have lots of situations where this is going to happen. there is a solution without having to create that number of tables?

Note:Obviously we must bear in mind that the solution does not complicate future queries, select, sort and query multiple tables that mix when reporting

rkmax
  • 17,633
  • 23
  • 91
  • 176

1 Answers1

1

If your priority is avoiding the proliferation of the link tables, you can use inheritance (aka. category, subclassing, generalization hierarchy):

enter image description here

No matter how many child entities Item has, you always need only one link table (PersonItem).

Unfortunately, inheritance is typically not directly supported by today's DBMSes so you'd have to represent it manually using either "all classes in one table" or "class per table" of these 3 strategies ("concrete class per table" would still proliferate link tables). This will increase the complexity in some cases, so if your priority is keeping queries simple, you are probably better off sticking with the current design (though this depends on the kinds of queries you intend to run - some may actually be simpler with inheritance).

BTW, the model above will not let different Hobby and Thing share the same Id. I'm guessing this is not important to you, but in case it is, this is an argument for the model without inheritance (or you'd need to include the type in the Item's PK).

Community
  • 1
  • 1
Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167
  • I've been thinking in this ![Model][http://i.imgur.com/z8ehN.png] but the queries may be complicated – rkmax Jun 06 '12 at 14:45