本地主键还是自动生成的? [英] Native primary key or auto generated one?

查看:165
本文介绍了本地主键还是自动生成的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常使用原生主键(即现有列或列组合)更好,还是将主键设置为自动生成整数行?

As a rule is it better to use native primary keys (ie existing columns or combination of columns) or set your primary key to an auto generating row of integers?

EDIT:

已经指出,这非常类似于这个问题

这里的共识是使用代理键,这是我的自然倾向,但我的老板告诉我我也应该尽可能使用自然钥匙。他的建议可能是最好的这个特定的应用程序,因为行中的名称唯一标识它,我们需要保持查看旧数据的能力,因此对名称/规则的任何更改将意味着新的唯一行。

The consensus here is to use surrogate keys, which was my natural inclination, but my boss told me I should also use natural keys where possible. His advice may be best for this particular application, as Name in row uniquely identifies it and we have a need to maintain the ability to view old data, thus any changes to the name/rule is going to mean new unique row.

虽然这里的答案都有帮助,但大多数都是基于主观的这里是你应该,而不是援引来源。

While the answers here are all helpful, most of them are based on the subjective "here is what you should", and do not cite supporting sources. Am I missing some essential reading or are the best practices database design highly subjective and/or application dependent?

推荐答案

这是一个漂亮的

  • How do you like your primary keys?
  • What’s the best practice for Primary Keys in tables?
  • Which format of primary key would you use in this situation.
  • Surrogate Vs. Natural/Business Keys
  • Should I have a dedicated primary key field?

这篇关于本地主键还是自动生成的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆