Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DB design: Should I use constraints within a table or a new table

I inherited a large existing DB and I'd like to know if I should refactor it because 95% of my queries require joining at least 4 tables.

The DB has a 5 tables that only have an ID and Name column with less than 20 rows. I assume the author did this so he could change the names there and not change them in the other tables, but many of those tables are only referenced in one other table. Should I refactor these small 2 column tables into the a larger table and add a constraint to the column so users can't input incorrect names instead of having seperate tables?

like image 500
j40 Avatar asked Dec 12 '22 10:12

j40


1 Answers

Resist that urge. From your description I can deduce that the existing design is solid and probably well normalized. Your refactoring may actually undo a good db structure.

If you are bothered by writing a lot of joins in your queries I would suggest creating views to mitigate the boilerplate.

...the author did this so he could change the names there not change them in the other tables...

That is evidence of good design and exactly what you should strive for in a normalized database.

like image 116
Paul Sasik Avatar answered May 18 '23 17:05

Paul Sasik