How would inheritance be used in MySQL?

Viewed 8432

So I'm reading a book on database design principles and came on the chapter about inheritance, but I'm confused on how I could "connect" sub classes with their super class in MySQL ?

The table structure would, for example, look like this enter image description here

So how would I relate these two sub classes with their super class so that I could easily do a query similar to " hey, get me a correct contract type for a Person he is assigned to ".

A person could have one of each, or even both of them, if, for example, a Person is a student doing a part time job as a lecturer as well to finance it's schoolarship, or a Lecturer on some kind of extra course ( so he is a student as well as a lecturer ).

4 Answers

For the implementation of supertype and subtype, one must first extract ALL of the common attributes into the supertype. Next, create a lookup table that contains a reference to EVERY subtype that is included in the superclass. Each subtype is a one-to-one relationship with the supertype sharing the same Id as a primary key. This cannot be implemented in a RDBMS without some serious trigger nonsense. Therefore, it's wise to implement this in application code, in the business layer, inside a child, extended from an abstract table class, that represents any table. Don't forget to implement transactions for entries into this use case.

Related