Should every MySQL table have an auto-incremented primary key?

后端 未结 3 1912
半阙折子戏
半阙折子戏 2021-02-15 15:35
  • I understand the value of primary keys.
  • I understand the value of indexes.

Should every MySQL table have an auto-incremented prim

3条回答
  •  我寻月下人不归
    2021-02-15 16:05

    I am a huge fan of surrogate keys. I have yet to see a scenario where I would prefer not use one.

    I would say Yes.

    Read up on this answer Surrogate vs. natural/business keys

    Edit

    I will change my answer to include the following:

    There are certain scenarios that I now use the actual value as a surrogate key:

    DimDate (20151031, 20151101, 20151102....) DimZipCode (10001, 10002, 10003...)

    Everything else gets Surrogate Keys.

提交回复
热议问题