Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How mysql modifies the value of a primary key

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces mysql how to modify the value of the primary key of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this mysql how to modify the value of the article will have a harvest, let's take a look at it.

Method: 1, delete the primary key with alter table, the syntax is "alter table table name drop primary key;"; 2, use alter table to add the primary key again, 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 does mysql modify the value of a primary key

The first step: first need to know that mysql to modify the primary key to delete the original primary key constraint, and then add a new primary key to achieve the effect of modifying the primary key, here modify the primary key of the coal_3 table.

Enter "alter table coal_3 drop primary key;" to delete the previous primary key constraint of the coal_3 table, as shown in the following figure:

After seeing that the sql statement has been successfully executed, the original primary key has been deleted. It is important to note that if the primary key is automatically incremented, the primary key needs to be removed first, and then deleted, as shown in the following figure:

Step 2: execute the "alter table coal_3 add primary key (id);" statement and add id as the primary key of the coal_3 table, as shown in the following figure:

Step 5 so that mysql successfully modifies the primary key, as shown in the following figure:

This is the end of the article on "how mysql modifies the value of primary keys". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to modify the value of primary keys in mysql". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report