Hello. Suppose there is a table with columns user_id and user_group , the remaining columns are not important. One user can belong to several groups, that is, it turns out that user_id not unique. It is obvious that several users can belong to one user_group , therefore user_group not unique.

But the user_id and user_group is unique, so the question arises - is it possible to make a primary key in two columns and in general, is it normal? How to organize a table in this case?

  • 3
    Absolutely normal, binding tables are usually done this way. just declare the primary key(user_id, user_group) - Mike
  • It is possible in two columns. - Visman
  • @Mike and then the values ​​of user_id / user_group can be repeated, and only a pair will be considered unique? - Nik
  • @Nik Yes, that's right - Mike

0