In a database, what is the difference betwen a key and an index?

前端 未结 10 1631
伪装坚强ぢ
伪装坚强ぢ 2021-02-08 00:59

For example, in SQLServer, if I have an index with \'unique\' set on it, how is that different from a key?

How do I know when I want to use a Key vs. an Indexed field?

10条回答
  •  醉酒成梦
    2021-02-08 01:39

    A key uniquely identifies a row in a table. An index is the order of rows based a field in a table. A table can have multiple indexes, because an index can just be a certain order of a set fields the system uses to search on and then looks up the actual row. Technically, there can only be one key the system uses to identify a row. Most of the time, this is also the primary index, but it doesn't have to be.

提交回复
热议问题