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

前端 未结 12 1436
南笙
南笙 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:29

    Yes, a table should ALWAYS have a primary key... unless you don't need to uniquely identify the records in it. (I like to make absolute statements and immediately contradict them)

    When would you not need to uniquely identify the records in a table? Almost never. I have done this before though for things like audit log tables. Data that won't be updated or deleted, and wont be constrained in any way. Essentially structured logging.

提交回复
热议问题