Tuesday, November 22, 2011

Inheritace and ERD

You have three alternatives to translate class hierarchies into relational tables: - Create only a table for the superclass (all attributes and associations of subclasses are moved to the table corresponding to the superclass with the possibility of taking a NULL value) - Create only tables for the subclasses: All attributes and associations of the superclass are repeated in each subclass - Create tables both for the superclass and for each of the subclasses. In this case, the PK of the subclasses is at the same table a FK to the superclass (this ensures that all identifiers in a subclass table correspond to an existing identifier in the superclass table. A join between both tables allows to recover the full information of the element)
The best strategy depends on the problem (for instance, the number of attributes in each class, the number of levels in hierarchy, whether the hierarchy is disjoint or not,...)

No comments:

Post a Comment