简体   繁体   English

候选键SQL

[英]Candidate keys SQL

hi am recently learning about SQL and keys. 嗨,我最近在学习有关SQL和键的知识。

i am wondering if there is n attributes to a relation table how many possible Candidate keys would there be? 我想知道关系表是否有n个属性,可能有多少个候选键?

Each subset of the attributes of the relations can be a candidate key. 关系的属性的每个子集都可以是候选键。 So the number is equal to the number of the subsets of a set of n elements, that is 2 n 因此,该数量等于一组n个元素的子集的数量,即2 n

Edited 已编辑

The original answer was 2 n -1, but it significant also to have the empty (or niladic) key. 最初的答案是2 n -1,但是拥有空(或尼拉迪克)键也很重要。 A key of such kind implies that the relation has only one tuple. 这种键意味着该关系只有一个元组。 Thanks to @ErwinSmout for the clarification. 感谢@ErwinSmout的澄清。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM