Home > Database > Mysql Tutorial > How to change the primary key in mysql

How to change the primary key in mysql

王林
Release: 2020-09-05 13:14:58
Original
10807 people have browsed it

Mysql method to change the primary key: First execute the [alter table table name drop primary key;] command to delete the primary key; then execute the [alter table table name add primary key(id)] command to re-add the primary key.

How to change the primary key in mysql

Specific method:

(Recommended tutorial: mysql video tutorial)

For example, we want Delete the original primary key constraints of the coal_3 table and execute the command:

alter table coal_3 drop primary key;
Copy after login

It should be noted that if the primary key is set to auto-increment, you need to remove the auto-increment first and then delete the primary key.

(Related tutorial recommendations: mysql tutorial)

Then re-add the primary key, the command is as follows:

alter table coal_3 add primary key(id)
Copy after login

The above is the detailed content of How to change the primary key in mysql. 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