I have basic generalisation schema in database, I have superclass vehicle, and its subclases automobiles, motorcycles. I implemented those by creating table for each superclass/subclas combination, thus I created automobiles and motorcycles tables.
But now I have problem, I need to set FK from my other table to “both” these tables. So “Person” has either motorcycle or automobile, but never both and never more from one kind. How can I link table Persons with Automobiles and Motorcycles to achieve that? Thank you very much.
Don’t do it like that – it will just result in pain and lots of expensive joins.
Have one table for the entire class heirarchy and have a “discriminator” column which determines the type either numerically or symbolically. Quick example using psuedo-sql: