I have a table of entities. For example purposes, lets call them Vehicles
: Car
, Boat
, Motercycle
, etc.
I'd ideally like to place all entities in a single Vehicles
table because a lot of related tables (VehicleRatings
, VehicleComments
, VehicleHistory
, etc) are going to apply to any entity, not just one of them.
But some of the entities have a few individual properties that aren't shared with the other entity types. Right now, there is only 1 extra property for one entity, and 2 for another. I expect there might be a few more that get identified later on, but not many overall.
How do I know when it's better to create a child table for each entity type to store these individual properties, as opposed to just adding an extra column in the parent Vehicles
table? Is there any questions I can ask myself to help determine this answer?
I am looking to optimize for query performance primarily, followed by ease of maintenance.
Best Answer
From a logical ERD perspective, the appropriate design is clearly the entity supertype/subtype pattern. What you're wrestling with is how to implement this from a physical perspective.
Like a lot of data modeling issues, there is no hard and fast rule. You are looking at a compromise. Do you want a fair bit more complexity in your application logic and queries (supertype/subtype) or do you want the risk that your application logic might not properly enforce your constraints and that a Car record in your consolidated
vehicle
table might get a non-null value in theanchor_weight
column?The kinds of things that you should consider in deciding how to trade off these alternatives are:
At the end of the day, you are going to make a practical decision based on what is most important to you. Whatever you decide will have pros and cons - but they will be your pros and cons.