Home > Database > Mysql Tutorial > body text

What is the statement to delete primary key in mysql

WBOY
Release: 2022-05-26 16:54:24
Original
7408 people have browsed it

In mysql, the statement to delete the primary key is "Alter table tb drop primary key;"; the Alter table statement is used to modify the structure of the table, and drop is used to indicate deletion. If the columns in the table have dynamic growth attributes , you need to delete the auto-increment first before you can delete the primary key.

What is the statement to delete primary key in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What is the statement to delete the primary key in mysql

1) If the primary key id is not automatically incremented

The syntax for deleting the primary key is as follows:

Alter table tb drop primary key;//删除主建
Copy after login

What is the statement to delete primary key in mysql

What is the statement to delete primary key in mysql

##(2) If the primary key id is automatically incremented

The syntax for deleting a primary key is as follows:

Alter table tb change id id int(10);//删除自增长
Alter table tb drop primary key;//删除主建
Copy after login

What is the statement to delete primary key in mysql

What is the statement to delete primary key in mysql

Extended knowledge:


Add a primary key

(1) If the primary key id is not automatically incremented

Alter table tb add primary key(id);
Copy after login

(2) If the primary key id is automatically incremented

Alter table tb add primary key(id);
Alter table tb change id id int(10) not null auto_increment;
Copy after login
Recommended learning:

mysql video tutorial

The above is the detailed content of What is the statement to delete 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!