natural key vs surrogate key an innodb foreign key

前端 未结 2 662
遥遥无期
遥遥无期 2020-12-16 00:10

A question:

I have 2 tables:

Product
id INT
name VARCHAR(64)
something TEXT
else INT
entirely BOOL

and

Ingredient
i         


        
2条回答
  •  孤城傲影
    2020-12-16 01:01

    For this case I'd prefere surrogate keys because

    1. the name of a product or an ingredient may change, especially if your content is user generated (e.g. typos or there are several possible names for an item)
    2. your natural keys will be much longer than and therefore be less efficient

提交回复
热议问题