Does a user to group (many-to-many) relational table in MySQL needs PRIMARY KEY? -
I did some research but could not get a clear answer.
I have a simple multiple-to-many relational table, user_id
will be foreign and group_id
will be foreign, whether to add a primary key reason?
What if you ever want to do something more interesting with that table (let's call it Table A Say), such as closing the satellite of A and connecting several other table B to another several-to-many tables?
Maybe there is a time when you have a specific a fixed
group_id
?
Basically, if you ever want to referenced Table A, or Table A is a parent of another table, then user_id requires a primary key on table A. . And in my mind, in relational DB, it is very likely that you want to refer to it at some point.
So I say add an auto-increment PK (assuming that you are ok with duplicate user_id, group_id
rows, like @ leslie said in a comment Besides, note that if you give it an auto increment, then by entering an index on now user_id
and <
Comments
Post a Comment