Answer the question
In order to leave comments, you need to log in
Whether to put primary key on the linking table?
Hello, I vaguely understand sql unfortunately, and therefore the question arose.
There are three tables
. Is it necessary to set the primary_key in the brands_state table to the id_brand and id_group fields (id_group and id_brand integer of course, there is a little wrong on the diagram)?
Answer the question
In order to leave comments, you need to log in
Without a deep understanding, it is worth asking yourself an immutable rule "every table must have a primary key." In the future, someday it will be possible to reach the nirvana of a situation where pk should not be.
I still don’t understand why everyone recommends setting the primary key to the brands_state table if it is a link table.
There are two foreign keys.
I would not bet (and I don’t bet on such pk link tables, they are not needed in them).
If pk is an attempt to make the relationship unique (so that duplicates are not generated), then this is a question for the application logic, which mindlessly duplicates rows consisting of two foreign key fields, and not for SQL constraints.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question