Home  >  Article  >  Database  >  How to change the primary key in mysql

How to change the primary key in mysql

王林
王林Original
2020-09-01 15:34:3110767browse

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;

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)

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!

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