Relational database design question - Surrogate-key or Natural-key?

前端 未结 10 2171
忘了有多久
忘了有多久 2020-11-27 22:33

Which one is the best practice and Why?

a) Type Table, Surrogate/Artificial Key

Foreign key is from user.type to type.i

10条回答
  •  天命终不由人
    2020-11-27 23:16

    I believe that in practice, using a natural key is rarely the best option. I would probably go for the surrogate key approach as in your first example.

    The following are the main disadvantages of the natural key approach:

    • You might have an incorrect type name, or you may simply want to rename the type. To edit it, you would have to update all the tables that would be using it as a foreign key.

    • An index on an int field will be much more compact than one on a varchar field.

    • In some cases, it might be difficult to have a unique natural key, and this is necessary since it will be used as a primary key. This might not apply in your case.

提交回复
热议问题