- Local time
- Today, 02:11
- Joined
- Jul 9, 2003
- Messages
- 17,344
I realised that all my separate lookup tables would go into one table, and I've been doing it like that for years. However I happened upon these comments on stack overflow and I'm not really understanding what the poster is getting at? Am I missing something important? Should I use a separate table for each lookup?
Poster's Comments HERE:-
http://stackoverflow.com/questions/...use-constraints-within-a-table-or-a-new-table
Sounds like what you have are lookup tables. Let me tell you what happens when you decide to put all lookups in one table with an additional column to specify which type it is. First instead of joining to 4 different tables in one query, you have to join to the same table 4 times. There ends up being more contention for the resources in the "one table to rule them all". Further, you lose FK constraints. That means you eventually lose data integrity. So if one lookup is state, nothing will prevent you from putting the id values for a different lookup for customer type in the state id column in the customeraddress table. When the lookups are separate you con enforce that relationship.
Suppose instead of one big table you decide to have a constraint on the column for customer type. Constraints are now enforced but you have a problem when they need to change. Now you have to alter the database in order to add a new type. Again usually this is a very bad idea especially when the table gets large.
Poster's Comments HERE:-
http://stackoverflow.com/questions/...use-constraints-within-a-table-or-a-new-table
Sounds like what you have are lookup tables. Let me tell you what happens when you decide to put all lookups in one table with an additional column to specify which type it is. First instead of joining to 4 different tables in one query, you have to join to the same table 4 times. There ends up being more contention for the resources in the "one table to rule them all". Further, you lose FK constraints. That means you eventually lose data integrity. So if one lookup is state, nothing will prevent you from putting the id values for a different lookup for customer type in the state id column in the customeraddress table. When the lookups are separate you con enforce that relationship.
Suppose instead of one big table you decide to have a constraint on the column for customer type. Constraints are now enforced but you have a problem when they need to change. Now you have to alter the database in order to add a new type. Again usually this is a very bad idea especially when the table gets large.