主键与唯一约束? [英] Primary Key versus Unique Constraint?

查看:140
本文介绍了主键与唯一约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在设计一个全新的数据库。在学校,我们总是学会在每个表中放一个主键。



我读了很多文章/讨论/新闻组的帖子说,最好使用唯一约束

你的观点是什么?

解决方案

您能提供这些文章的参考吗?



我没有理由改变尝试和真正的方法。毕竟,主键是关系数据库的基本设计特性。



使用UNIQUE来提供相同的目的对我来说听起来真的很奇怪。他们的理由是什么?



编辑:我的注意力回到了这个老的答案。也许你读的关于PK对UNIQUE的讨论处理的人做一个PK的唯一目的,强制其唯一的目的。答案是,如果它是一个键,那么使它的键,否则使其UNIQUE。


I'm currently designing a brand new database. In school, we always learned to put a primary key in each table.

I read a lot of articles/discussions/newsgroups posts saying that it's better to use unique constraint (aka unique index for some db) instead of PK.

What's your point of view?

解决方案

Can you provide references to these articles?

I see no reason to change the tried and true methods. After all, Primary Keys are a fundamental design feature of relational databases.

Using UNIQUE to serve the same purpose sounds really hackish to me. What is their rationale?

Edit: My attention just got drawn back to this old answer. Perhaps the discussion that you read regarding PK vs. UNIQUE dealt with people making something a PK for the sole purpose of enforcing uniqueness on it. The answer to this is, If it IS a key, then make it key, otherwise make it UNIQUE.

这篇关于主键与唯一约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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