Should I create many ID for a same Person/entity in my DB?

All we need is an easy explanation of the problem, so here it is.

In my model, I must store the name of the teacher of some kids and the classroom in which the teachers work, let’s say. All of the hundreds of teachers in the schools have 1 and only 1 classroom, except 2 teachers, which have 2 classrooms and there is no way we can remove one classroom (we MUST keep the 2 classrooms)… do you know of a way to handle this exception ? Knowing that it might happen with other teachers in the future.

The only solution I found so far goes as follow:

Kid Table

Kid ID (PK)

Teacher ID

Teacher Table

Teacher ID (PK)

Teacher Name

Classroom ID

And to have 2 teacher ID (or more) for the very few teachers who have more than 1 classroom. I do need the teacher name in the teacher table to be able to produce stats based on the teachers (no matter the number of teacher ID related to any given teacher).

Does it this model make sense ? is there a better way to do it ?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Properly normalized it will have 3 tables as follows:

Kid

kid_id (pk)
classroom_id (fk to Classroom)

Teacher

teacher_id (pk)
name

Classroom

classroom_id (pk)
teacher_id (fk to teacher)

This way you have no duplication and no update anomalies.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply