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

前端 未结 10 1623
伪装坚强ぢ
伪装坚强ぢ 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:36

    A key should be the business model's unique identifier for the row. A uniquely indexed column could be considered an "alternate key." Generally SQL servers will create a unique index for primary keys automatically.

    I should also mention that you can index non-unique columns; indices such as these are used for speeding up queries over the indexed columns.

提交回复
热议问题