The difference between primary key, unique key and key in MySQL index

primary key

  • Can uniquely identify each row of data in the database
  • The primary key must contain a unique value
  • The default primary key index
  • There can only be one primary key index in a table

unique key

  • Establish a unique index, that is, each row of data under the index is not repeated, and is mainly established to prevent duplication of inserted data
  • There can be multiple unique indexes in a table

key

  • The simplest and common index is generally used to speed up the query, and the index is the same, in most cases it is used as a foreign key

Guess you like

Origin blog.csdn.net/xiaole060901/article/details/113114635