Is it OK not to use a Primary Key When I don't Need one

前端 未结 12 1316
南笙
南笙 2020-12-17 23:06

If I don\'t need a primary key should I not add one to the database?

12条回答
  •  有刺的猬
    2020-12-17 23:27

    Well...

    Each table in a relational DB needs a primary key. As already noted, a primary key is data that identies a record uniquely...

    You might get away with not having an "ID" field, if you have a N-M table that joins 2 different tables, but you can uniquely identifiy the record by the values from both columns you join. (Composite primary key)

    Having a table without an primary key is against the first normal form, and has nothing to do in a relational DB

提交回复
热议问题