Three common strategies:
-
Create a table for each class in the hierarchy that contain the properties defined for each class and a foreign key back to the top-level superclass table. So you might have a
vehicletable with other tables likecarandairplanethat have avehicle_idcolumn. The disadvantage here is that you may need to perform a lot of joins just to get one class type out. -
Create a table for each class in the hierarchy that contains all properties. This one can get tricky since it’s not easy to maintain a common ID across all the tables unless you’re using something like a sequence. A query for a superclass type would require unions against all the tables in question.
-
Create one table for the entire class hierarchy. This eliminates joins and unions but requires that all of the columns for all class properties be in one table. You’ll probably need to leave most columns nullable since some columns won’t apply to records of a different type. For example, the
vehicletable might contain a column calledwingspanthat corresponds to theAirplanetype. If you make this column NOT NULL then any instance of aCarinserted into the table will require a value forwingspaneven though a value ofNULLmight make more sense. If you leave the column nullable you might be able to work around this with check constraints but it could get ugly. (Single Table Inheritance)