I’m trying to design an application that will use a DB to store some information about boxes.
These boxes are located at a specific, predefined site such as “Garage”, “Living Room”, etc. Locations that could easily be chosen with a dropdown box . But sometimes they can be somewhere else like “Joe’s” that would pretty much be specific and mostly non repeatable.
So my question is how to store this in the DB?
My first idea was to make a simple relation with a table with boxes
BOXES
| ID_BOX | ID_LOCATION |
| 1 | 1 |
| 2 | 3 |
And another table with the locations
LOCATION
| ID_LOCATION | LOCATION |
| 1 | Garage |
| 2 | Living Room |
But how can I put the extra options in here? Add them “temporarily” to the Locations Table? Or make an “Other” field and store this information somewhere else?
If these locations are sure to be pretty much unique and you do not need persistence once the object has been moved or deleted you could add an SQL function when deleting to check if there are any objects at a certain location, if there are non: delete the location.
If that sound dangerous or not a good idea (for most cases it will be a bad idea) you could add a column to BOXES to specify if the location is in a regular place or in a temporary place, create a table for each and make the relation in a 4rd table. This way you could only add the registers in REGULAR_LOCATIONS to your drop menu and add the ‘others’ option to write into TEMP_LOCATIONS
Or even better, you could add a column to the locations table and specify if they are regular or not, if they aren’t you won’t show them in the drop down menu. And you get to keep you r current scheme.