Answer the question
In order to leave comments, you need to log in
Database normalization?
Everything is very good when we divide the database into minimally useful information with foreign keys, but let's say the situation is:
I need to write to the database, as an abstract example, information about a musical group, its composition, etc.
One group may have several different compositions - in different eras of existence.
Each musician in the composition can have several instruments on which he plays.
Okay, let's create tables:
"Musicians"
"Instruments"
"Groups"
"Line-ups"
"Musicians in the line-up"
"Musician's instruments in the line-up".
So in the end, if I want to add a new group page, how many times do I have to INSERT? Even if these musicians and instruments are already initially in the table, the following will happen:
1. Insert a new group entry into the "Groups" table.
2. Insert a record about the first composition in the table "Group compositions".
3. Insert a record about the second composition in the table "Group compositions".
3. Insert a record about musician-1 of the first composition in the table "Musicians in the composition".
4. Insert an entry about the first musician's instrument-1 into the table "Musician's instruments in the composition".
5. Insert an entry about the second musician's instrument-1 into the table "Musician's instruments in the composition".
6.
7. Insert an entry about the first instrument of the musician-2 in the table "Musician's instruments in the composition".
8. Insert a record about musician-3 of the first composition in the table "Musicians in the composition".
...
And if there were 10 of them in the composition of the musicians and the compositions themselves were 3-4? So my 10 requests will easily turn into a good hundred, and all to add seemingly simple information ...
It seems to me, or will it be too much? After all, you want not only to break the database structure into minimally useful information, but also in order not to get a large number of requests that consume memory, etc., especially if this all refers to information that will be updated very often...
SELECT queries will be even simpler, but INSERT, and all the more so since everything is connected by foreign keys, for example, the "Musicians in the line-up" table needs the PRIMARY KEY of the "Group line-up" table for identification, and you first need to get it in php and only then do the next INSERT into another table, that is, all these queries will not even go in one transaction.
What now, through a comma, list the IDs of the necessary elements and everything in one or two tables? But it's not possible to make foreign keys that way, which doesn't sound like a good idea either...
Anyway, thanks if you're reading this, I'd love to see what you would do.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question