This question is in the context of adding a new field or fields to a table. - Specifically in my following example, whether equipment
's column to reference make-model.ID
should be one field or two.
Say, there exists a table named make-model
that stores dependent information.
ID | Name | Parent |
---|---|---|
1 | Acme | NULL |
2 | 1000 | 1 |
3 | Anvil | 1 |
4 | Omni | NULL |
5 | 1000 | 4 |
6 | Photocell | 4 |
This table is meant to represent a category/subcategory relationship that can be represented as:
Acme
- 1000
- Anvil
Omni
- 1000
- Photocell
Notice that there are two 1000
models, but they belong to different makes, this is why the ID
column is the key.
There is also a table named equipment
that stores information about the equipment, including the make/model.
Based on user input, the breed is set and could be specific to Anvil
or stop at Acme
. (Theoretically this could be more than two levels deep, but I'm keeping it at two for this question.)
In the program that the user uses to view/modify this data, they will see two fields, one that would show the higher level (Acme) and one that would show the more specific level (Anvil).
As far as actual columns on the Equipment
table, what is the benefit of one column storing the most specific id given (3 if Anvil, 1 if Acme) or two columns, one for each level?
So, for example Table A:
ID | Name | Make-Model |
---|---|---|
1 | Max | 2 |
2 | Spot | 3 |
3 | Fluffy | 4 |
Vs. Table B:
ID | Name | Make | Model |
---|---|---|---|
1 | Max | 1 | 2 |
2 | Spot | 1 | 3 |
3 | Fluffy | 4 | NULL |
My question is about the benefit of Table A's design vs. Table B's design
As far as getting the information, a simple enough query can find the parent of any given id or determine if it doesn't have any level above it - so the information is accessible either way.
The column won't store the pretty name, only the numerical id referencing the breeds
table, so readability in the database isn't too much a factor.