主键是否通过? [英] Are primary keys passé?

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

问题描述

小键提供了什么独特的功能?



虽然我用舌头紧紧地刻在脸颊上的问题,我的问题是严重的。在任何火焰开始之前,我不是说建立数据库没有约束或引用完整性。但是,到目前为止,我可以告诉SQL Server可以消除主键关键字。




  • 唯一索引涵盖,很好,唯一性

  • 基于列的非可空性涵盖非可空性PK的要求

  • PK不需要集群,所以不是这样的。

  • 外键可以而且经常使用唯一的索引,而不是PKs

  • 即使MSDN声明创建唯一索引来强制PK的唯一性



我同意,逻辑上一个主键有一个关于数据模型的意图,但是呢? [讽刺]哦,我们确实获得那个小图标SSMS在设计表时显示! [/ sarcasm]






编辑



从评论中可以看出,我没有像以前那样清楚地提出这个问题。我同意主键从逻辑角度很重要。



问:




  • 我应该选择一个int或一个varchar为我的PK

  • 做PK必须被聚类,或者我如何识别什么应该聚集

  • 如何我唯一标识行



我的目的是问PK提供哪些功能不能合理使用其他功能实现?我不是建议在这里疯狂 - 比如使用触发器强制执行唯一性而不是唯一的约束/索引。合理的是这里的一个关键词 - 使用唯一的索引/约束似乎非常类似于定义一个PK。

解决方案

不同的观点:



SQL是由ISO标准定义的语言。该标准具有强制功能和可选一致性功能。



如果您使用某些数据操作语言构建DBMS,那么您有权呼叫您的语言SQL 只有:



(a)您已经实现了标准规定的所有语法(强制功能),而
(b)您已实施的语言功能(所有必需的功能,至少都是必需的),还可以根据标准中所描述的行为进行准确的显示。



PRIMARY KEY语法是一个非常老的功能,它不是不可能的,这是强制性之一。从您的语言中删除这个词意味着您不能再合法地将您的语言称为SQL语言。大型商业供应商不太可能很快就会出现这样的举动。


What unique functionality do Primary Keys provide?

While i titled the question with tongue firmly planted in cheek, my question is serious. Before any flames start, I'm not saying build a database without constraints or referential integrity. As far I can tell, however, SQL Server could do away with the primary key key word.

  • Unique indexes cover, well, uniqueness
  • Column based Non-nullability covers the non-nullability requirement for PKs
  • PK's don't have to be clustered, so that's not it
  • Foreign keys can, and often are, implemented with unique indexes, rather than PKs
  • Even MSDN states that a unique index is created to enforce the PK's uniqueness

I do agree that logically a Primary Key coveys a bit of intention about a data model, but is that it? [sarcasm]Oh, and we do get that little Key icon SSMS shows when designing a table! [/sarcasm]


EDIT

From the comments, it seems clear I didn't ask this question as clearly as I thought. I agree that primary keys are important from a logical perspective.

I'm not asking:

  • should i choose an int or a varchar for my PK
  • do PK's have to be clustered, or how do i identify what should be clustered
  • how do i uniquely identify rows

My intention was to ask "what features do PK's provide that cannot reasonably be implemented using other features?" I'm not suggesting going crazy here -- like using a trigger to enforce uniqueness instead of unique constraints/indexes. Reasonable is a key word here -- and using a unique index/constraint seems very similar to defining a PK.

解决方案

A completely different perspective :

SQL is a language that is defined by an ISO standard. That standard has "mandatory" features and "optional conformance" features.

If you build a DBMS with some data manipulation language, then you are entitled to call your language "SQL" only if :

(a) you have implemented ALL of the syntax prescribed by the standard ("mandatory" features) , and (b) all of the language features that you have implemented (all the mandatory ones as a minimum, but also the "optional" ones you "opted in" for), expose exactly the behaviour as defined/Described in the standard.

The "PRIMARY KEY" syntax is a very old feature, and it's not unlikely that it is one of those "mandatory" ones. Ditching the word from your language means you can no longer legitimately call your language SQL. Big commercial vendors are not likely going to make such a move any time soon.

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

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