Home>Article>Database> What is the statement to delete primary key in mysql

What is the statement to delete primary key in mysql

WBOY
WBOY Original
2022-05-26 16:54:24 7460browse

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;//删除主建

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;//删除主建

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);

(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;

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!

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