Reputation: 19396
I have a table components that has the general information for the pieces that can be used in a machine (reference, manufacture...). But I can have a very different types of pieces, for example, valves, engines... And so on. So each type of pieces has different type of specifications data.
For example, valve has information about its diameter, but the engine has information about his power. It has no sense to have information about the power of a valve.
I am thinking in two options. First, to have a unique table with all the data for the specifications, so I have many fields ValveDiamter
, ValveMaterial
.... EnginePower
, EngineType
, etc. In this case, the problem is that for a piece, I would have all the fields with null
value less the few fields with the information of the type of pice.
Other solution is to have one table of specifications for each type of piece. So I would have a table ValveSpecificaionts
, EngineSpecifications
, etc. This makes me to have a lot tables, but only with the information that I need according to the type of piece.
I wonder what will be the best option. Any other alternative?
Upvotes: 0
Views: 65
Reputation: 14893
To make a fully informed decision we would need more information (mostly about how it will be used, and how the pieces interrelate, if at all), but as a general rule, I would recommend using more tables with only the columns that apply to each piece.
This has the advantage of being more tailored to the piece which is easier to work with and more effecient for many (but not all!) typical usage patterns. This is also likely the pattern you would see if you deliberately normalize your tables, which is often worth doing.
Along with that, it is likely to be help prevent certain types of inconsistencies (such as ensuring that a piece does not receive an attribute that doesn't apply to it).
Upvotes: 1
Reputation: 11801
It sounds like you're deciding between 1 table with many fields (where most fields will be unused for any one record), and many tables with a few fields (where most fields will be almost always used). Here's a few questions which may help:
Upvotes: 2
Reputation: 13030
There are a few different ways to deal with something like this:
The best one depends on the total number of attributes, the number of attributes in common, and whether or not the attributes need to be searchable.
Upvotes: 1