Default Value Storage
-
16-09-2019 - |
Question
I have the following three tables:
- Item
- Code
- ItemCode (many to many relationship between Item and Code)
And then I have the following sample data on the third table:
Item | Code
-----+-----
001 | A
002 | A
003 | B
There's a possibility that a new Item is added but does not have a code yet. I will assign a default code for this Item, say "Z".
My question is, which is better:
- adding an entry in the ItemCode table every time a new Item is created (with the code value to "Z")
OR
- retrieve the default value from configuration file (and keep the ItemCode table clean from default value entries)
Additional consideration: the default code will always be returned, regardless whether an Item have been assigned a Code or not. So the result from the above data would be:
Code A: Item 001, Item 002
Code B: Item 003
Code Z: Item 001, Item 002, Item 003
Solution
Either: don't put a row in ItemCode yet until you know the code (read from file)
Or: make the Code column nullable in ItemCode so it's Unknown/Undefined (depending on your pedantry) and left join/isnull.
I personally don't like storing "default" or "placeholder" values. If you don't know the code, then put nothing. What if you have 2 new items for example?
The other question is: can you deal with this in the client?