主键和索引键之间的区别是什么 [英] What is the difference between a primary key and a index key
问题描述
任何人都可以告诉我主键和索引键之间的区别。何时使用索引键。/ / />
主键是一种特殊类型的索引, p>
- 只能有一个;
- 不能为空;
您倾向于使用主键作为最多的行的自然唯一标识符(例如社会安全号码,员工ID等,虽然有一个思想学派,你应该总是使用人工代理键为此)。
$ b $另一方面,索引可用于基于其他列的快速检索。例如,员工数据库可能有您的员工号码作为主键,但也可能有您的姓氏或您的部门的索引。
这两个索引姓氏和部门)将不允许NULL(可能)并允许重复(几乎肯定),并且它们将有助于加快查找任何人的名称(例如)姓名Corleone或在HitMan部门工作。
Can any one tel me what is the difference between a primary key and index key. And when to use a index key.??/
A primary key is a special kind of index in that:
- there can be only one;
- it cannot be nullable; and
- it must be unique.
You tend to use the primary key as the most natural unique identifier for a row (such as social security number, employee ID and so forth, although there is a school of thought that you should always use an artificial surrogate key for this).
Indexes, on the other hand, can be used for fast retrieval based on other columns. For example, an employee database may have your employee number as the primary key but it may also have an index on your last name or your department.
Both of these indexes (last name and department) would disallow NULLs (probably) and allow duplicates (almost certainly), and they would be useful to speed up queries looking for anyone with (for example) the last name 'Corleone' or working in the 'HitMan' department.
这篇关于主键和索引键之间的区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!