Home >Database >Mysql Tutorial >Is the primary key necessary for MySQL?

Is the primary key necessary for MySQL?

(*-*)浩
(*-*)浩Original
2019-05-07 14:35:569053browse

The primary key of MySQL is necessary. Adding a primary key to all tables is a good habit when using the database. The primary key will help users avoid introducing duplicate data problems when migrating data.

Is the primary key necessary for MySQL?

What is a primary key?

Each row in the table is uniquely determined by the primary key (PK). When you create a table, you must specify the columns that make up the primary key. These columns are called primary key columns. The primary key column must have a value. You must ensure that the combination of values ​​for the primary key columns uniquely identifies a row. During subsequent use, the type of the primary key column cannot be changed.

Take HybridDB for MySQL as an example:

HybridDB for MySQL has no sharing between logical partitions, so uniqueness can be guaranteed within a partition, but the partitioning Ranges will not be able to maintain all database and table constraints, even uniqueness constraints.

Using the AUTO_INCREMENT column can ensure global uniqueness. (Recommended course: MySQL Tutorial)

The above is the detailed content of Is the primary key necessary for MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn