Home > Database > Mysql Tutorial > body text

What is mysql primary key?

藏色散人
Release: 2020-10-12 14:08:00
Original
30922 people have browsed it

In MySQL, the full name of the primary key is "primary key constraint". It is a column or a combination of multiple columns. Its value can uniquely identify each row in the table. It can enforce the entity integrity of the table; the primary key Its function is to determine the uniqueness of the data, mainly for foreign key association with other tables, as well as modification and deletion of this record.

What is mysql primary key?

#What is the primary key in mysql?

Primary key (PRIMARY KEY), also called "primary key constraint".

MySQL primary key constraint is a column or a combination of multiple columns whose value can uniquely identify each row in the table.

Such a column or columns are called the primary key of the table, through which the entity integrity of the table can be enforced.

The primary key is mainly used for foreign key associations in other tables, as well as modification and deletion of this record.

mysql The role of the primary key

1. The main role is to determine the uniqueness of the data. For example, ID=1,NAME=Zhang San. If we want to find this data in the database, we can use select * from table where id=1, so that we can find Zhang San. And this Zhang San can also have the same name, so ID is used as the primary key.

2. insert into is an insertion operation. When the ID is set as the primary key, and then inserting the same primary key value, an error will be reported and will not be updated. If you want an update, you must execute UPDATE.

①PRIMAPY means primary key, which means that the defined column value is unique in the table and cannot be repeated.

②AUTO_INCREMENT can be understood as automatic increment. Every time a record is added, the value will automatically increase by 1.

Such as:

CREATE TABLE `table name` (
`id` smallint(6) unsigned NOT NULL auto_increment,
`name` varchar(16) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
如果你insert into tablename (id,name) values ('','sadfa');
Copy after login

Related recommendations: "MySQL Tutorial"

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template