Home  >  Article  >  Database  >  Can the primary key of phpmyadmin be repeated?

Can the primary key of phpmyadmin be repeated?

angryTom
angryTomOriginal
2019-10-18 13:02:541858browse

Can the primary key of phpmyadmin be repeated?

Can the primary key of phpmyadmin be repeated?

The full name of the primary key (PRIMARY KEY) is "primary key constraint". A MySQL primary key constraint is a column or combination of columns whose value uniquely identifies each row in the table. Such a column or columns are called the table's primary key, by which the entity integrity of the table is enforced.

Primary key constraints define a primary key in the table to uniquely determine the identifier of each row of data in the table.

The primary key can be a certain column in the table or a combination of multiple columns. The primary key composed of multiple columns is called composite primary key.

Recommended: "mysql tutorial"

The primary key should comply with the following rules:

  1. Every A table can only define one primary key .

  2. The primary key value must uniquely identify each row in the table and cannot be NULL, that is, there cannot be two rows of data in the table with the same primary key value. This is Uniqueness Principle.

  3. A column name can only appear once in the composite primary key list.

  4. The composite primary key cannot contain unnecessary redundant columns. When a column of the composite primary key is deleted, if the primary key composed of the remaining columns still satisfies the uniqueness principle, then the composite primary key is incorrect. This is minimization principle.

Set primary key constraints when creating the table:

In the CREATE TABLE statement, the primary key is specified through the PRIMARY KEY keyword.
Specify the primary key while defining the column. The syntax rules are as follows:

<字段名> <数据类型> PRIMARY KEY [默认值]

[Example 1] Create the tb_emp 3 data table in the test_db database. Its primary key is id. The input SQL statement and running results are as follows Show.

mysql> CREATE TABLE tb_emp3
    -> (
    -> id INT(11) PRIMARY KEY,
    -> name VARCHAR(25),
    -> deptId INT(11),
    -> salary FLOAT
    -> );
Query OK, 0 rows affected (0.37 sec)
mysql> DESC tb_emp3;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | NO   | PRI | NULL    |       |
| name   | varchar(25) | YES  |     | NULL    |       |
| deptId | int(11)     | YES  |     | NULL    |       |
| salary | float       | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
4 rows in set (0.14 sec)

The above is the detailed content of Can the primary key of phpmyadmin be repeated?. 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
Previous article:phpmyadmin1045 errorNext article:phpmyadmin1045 error