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

前端 未结 10 1906
忘了有多久
忘了有多久 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:31

    Surrogate key for me too, please.

    The other might be easier when you need to bang out some code, but it will eventually be harder. Back in the day, my tech boss decided using an email addr as a primary key was a good idea. Needless to say, when people wanted to change their addresses it really sucked.

    0 讨论(0)
  • 2020-11-27 23:34

    I prefer to use the surrogate key. It is often people will identity and use the natural key which will be fine for a while, until they decide they want to change the value. Then problems start.

    0 讨论(0)
  • 2020-11-27 23:34

    If typeName is a natural key, then it's probably the preferable option, because it won't require a join to get the value.

    You should only really use a surrogate key (id) when the name is likely to change.

    0 讨论(0)
  • 2020-11-27 23:36

    You should probably always use an ID number (that way if you change the type name, you don't need to update the user table) it also allows you to keep your datasize down, as a table full of INTs is much smaller than one full of 45 character varchars.

    0 讨论(0)
提交回复
热议问题