What is the difference between a primary key and a index key

后端 未结 4 1367
無奈伤痛
無奈伤痛 2020-12-24 01:08

Can anyone tell me what is the difference between a primary key and index key. And when to use which?

4条回答
  •  误落风尘
    2020-12-24 01:45

    A key (minimal superkey) is a set of attributes, the values of which are unique for every tuple (every row in the table at some point in time).

    An index is a performance optimisation feature that enables data to be accessed faster.

    Keys are frequently good candidates for indexing and some DBMSs automatically create indexes for keys, but that doesn't have to be so.

    The phrase "index key" mixes these two quite different words and might be best avoided if you want to avoid any confusion. "Index key" is sometimes used to mean "the set of attributes in an index". However the set of attributes in question are not necessarily a key because they may not be unique.

提交回复
热议问题