代理与自然/商业密钥 [英] Surrogate vs. natural/business keys

查看:117
本文介绍了代理与自然/商业密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我们再来,旧的争论仍然出现...

Here we go again, the old argument still arises...

我们最好有一个业务密钥作为主键,或者我们宁愿有一个替代id(即SQL Server身份)对业务键字段有唯一约束?

Would we better have a business key as a primary key, or would we rather have a surrogate id (i.e. an SQL Server identity) with a unique constraint on the business key field?

请提供示例或证明来支持您的理论。

Please, provide examples or proof to support your theory.

推荐答案

两者。有你的蛋糕,吃它。

Both. Have your cake and eat it.

请记住,主键没有什么特别的,除了它被标记为这样。它只不过是一个NOT NULL UNIQUE约束,一个表可以有多个。

Remember there is nothing special about a primary key, except that it is labelled as such. It is nothing more than a NOT NULL UNIQUE constraint, and a table can have more than one.

如果你使用代理键,你仍然需要一个业务键来确保根据业务规则的唯一性。

If you use a surrogate key, you still want a business key to ensure uniqueness according to the business rules.

这篇关于代理与自然/商业密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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