Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

database design - best practice- one table for web form drop down options or separate table for each drop down options

I'm looking at the best practice approach here. I have a web page that has several drop down options. The drop downs are not related, they are for misc. values (location, building codes, etc). The database right now has a table for each set of options (e.g. table for building codes, table for locations, etc). I'm wondering if I could just combine them all into on table (called listOptions) and then just query that one table.

Location Table
LocationID (int)
LocatValue (nvarchar(25))
LocatDescription (nvarchar(25))

BuildingCode Table
BCID (int)
BCValue (nvarchar(25))
BCDescription (nvarchar(25))

Instead of the above, is there any reason why I can't do this?

ListOptions Table
ID (int)
listValue (nvarchar(25))
listDescription (nvarchar(25))
groupID (int) //where groupid corresponds to Location, Building Code, etc

Now, when I query the table, I can pass to the query the groupID to pull back the other values I need.

like image 722
HPWD Avatar asked Oct 15 '25 09:10

HPWD


2 Answers

Putting in one table is an antipattern. These are differnt lookups and you cannot enforce referential integrity in the datbase (which is the ciorrect place to enforce it as applications are often not the only way data gets changed) unless they are in separate tables. Data integrity is FAR more important than saving a few minutes of development time if you need an additonal lookup.

like image 182
HLGEM Avatar answered Oct 17 '25 03:10

HLGEM


You could do this. I believe that is your master data and it would not be having any huge amounts of rows that it might create and performance problems. Secondly, why would you want to do it once your app is up and running. It should have thought about earlier. The tables might be used in a lot of places and it's might be a lot of coding and most importantly testing. Can you throw further light into your requirements.

like image 24
arun.passioniway Avatar answered Oct 17 '25 03:10

arun.passioniway