Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Too sub-table or not to sub-table? that is the questi0n

I would like to know what the rule of thumb is regarding sub tables in a relational DB?

For example.

In the picture below i have replaced a few fields with sub-tables, because there can me multiple, but limited, instances of each

Is this overkill or the preferred way of DB design?

Second normal form (2NF) further addresses the concept of removing duplicative data:

  1. Meet all the requirements of the first normal form.

  2. Remove subsets of data that apply to multiple rows of a table and place them in separate tables.

  3. Create relationships between these new tables and their predecessors through the use of foreign keys.

enter image description here

P.S. I know a uuid is not a INT and will change it.

like image 289
morne Avatar asked Aug 21 '14 07:08

morne


1 Answers

If there will be more than one instance of the same data in the same table, there should be a relationship formed. Duplicate data is difficult to manage and you leave a lot of room for bugs.

As long as you don't have 2 references of the same data in one table, you're safe.

Database normalization is the process of organizing the fields and tables of a relational database to minimize redundancy.

See: Database normalization

You're on the right track.

like image 90
Zander Rootman Avatar answered Nov 08 '22 20:11

Zander Rootman