Composite Primary key vs additional “ID” column?

后端 未结 4 1032
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 00:24

If we had a table like this:

Books (pretend \"ISBN\" doesn\'t exist)

  • Author
  • Title
  • Edition
  • Year of publication
  • Price
4条回答
  •  时光取名叫无心
    2020-11-30 01:01

    In general, you don't want the primary key to change value. This is why blind or surrogate primary keys are used.

    Let's assume you created your Book table with Author as part of the primary key.

    Suppose you found out after about a year that you misspelled "Ray Bradbury". Or even worse, you misspelled "Rachael Bloom". Just imagine how many database rows you would have to modify to correct the misspelling. Just imagine how many index references have to be changed.

    However, if you have an Author table with a surrogate key, you only have to correct one row. No indexes have to be changed.

    Finally, database table names are usually singular (Book), rather than plural (Books).

提交回复
热议问题