代理与自然/业务键 [英] Surrogate vs. natural/business keys

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

问题描述

我们又来了,旧的争论仍然出现......

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.

推荐答案

两者.吃你的蛋糕.

请记住,主键没有什么特别之处,只是它被标记为这样.它只不过是一个 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天全站免登陆