How to modify the value of primary key in mysql
May 16, 2022 pm 04:45 PMMethod: 1. Use alter table to delete the primary key, the syntax is "alter table table name drop primary key;"; 2. Use alter table to re-add the primary key, the syntax is "alter table table name add primary key;" ;".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
How to modify the value of the primary key in mysql
The first step: First of all, you need to know that to modify the primary key in mysql, you must first delete the original primary key constraints, and then add a new primary key to achieve the effect of modifying the primary key. Modify the primary key of coal_3 table here.
Enter "alter table coal_3 drop primary key;" to delete the original primary key constraints of the coal_3 table, as shown in the following figure:
See that the sql has been executed The statement is successful and the original primary key is deleted. It should be noted that if the primary key is set to automatically increment, you need to remove the automatic increment first and then delete the primary key, as shown in the following figure:
Step 2: Execute the "alter table coal_3 add primary key(id);" statement and add the id as the primary key of the coal_3 table, as shown in the following figure:
In five steps, mysql successfully modified the primary key, as shown in the figure below:
Recommended learning: mysql video tutorial
The above is the detailed content of How to modify the value of primary key in mysql. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP's big data structure processing skills

How to optimize MySQL query performance in PHP?

How to use MySQL backup and restore in PHP?

How to insert data into a MySQL table using PHP?

What are the application scenarios of Java enumeration types in databases?

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to use MySQL stored procedures in PHP?

Performance optimization strategies for PHP array paging
