Are there any good reasons to have a database table without an integer primary key?

前端 未结 11 1853
感动是毒
感动是毒 2021-02-10 00:30

Although I\'m guilty of this crime, it seems to me there can\'t be any good reason for a table to not have an identity field primary key.

Pros: - whether you want to o

11条回答
  •  佛祖请我去吃肉
    2021-02-10 01:00

    I don't think every table needs a primary key. Sometimes you only want to "connect" the contents of two tables - via their primary key.

    So you have a table like users and one table like groups (each with primary keys) and you have a third table called users_groups with only two colums (user and group) where users and groups are connected with each other.

    For example a row with user = 3 and group = 6 would link the user with primary key 3 to the group with primary key 6.

提交回复
热议问题