Database primary keys and indexes associated

It has been unable to distinguish the relationship between primary keys and indexes, this sort for a rainy day

1, the primary key

  Is a primary key can uniquely identify a row in the table attributes or attribute groups, a table can have only one primary key, but can have multiple candidate.

  The main role of the primary key: 1, uniquely identifies a row. 2, as an object that can be referenced by a foreign key valid.

2, index

  Data table contains all records of the reference pointer.

the difference:

   A table can have multiple unique index, but only one primary key. 
  Primary key column does not allow null value, unique index column allows null values. 

  Primary key must be unique index, a unique index is not necessarily the primary key.

contact:

  A primary key is unique to the identification of database records, does not allow repeated recording, and the key can not be empty, the primary key is a special index. 

  In fact, primary keys and indexes are the key, but the primary key is a logical key, the index is a physical key, meaning that the primary key does not actually exist, and the index actually exists in the database, the primary key are generally required to build, is mainly used to prevent a table with the same records, generally can not build an index, but if you need to query the table, it is best to build, so you can speed up the retrieval speed.  

 

Note: popular to say the primary key is the page of a book, a book is a directory index.

 

Reference: https://www.cnblogs.com/ybygb-geng/p/9574169.html

Guess you like

Origin www.cnblogs.com/51python/p/11443540.html