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

The method of setting self-increment for fields by mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you mysql on the field setting self-increasing method, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

Mysql sets the self-incrementing method for the field: first open the mysql port; then add the self-incrementing field statement of the relevant MySQL, code [alter table album auto_increment=1;].

Mysql's method of setting self-increment for fields:

MySQL sets statements related to self-incrementing fields:

1 、 alter table album change ALBUM_ID ALBUM_ID bigint not null auto_increment; 2 、 alter table album auto_increment=1

Create:

Mysql > create table cc (id int auto_increment,name varchar (20), primary key (id))

Modify:

Mysql > alter table cc change id id int primary key auto_increment

Note: only int type and primary key can be used with auto_increment.

If you use hibernate as the persistence layer, use the identity type at the primary key ID.

For the choice of a table primary key, from the point of view of architecture design, it is better for the system to design a field that has nothing to do with business as the primary key, of course, this is bound to increase the size of the table data. some people may think that this side effect is not worth it and choose a field (or more fields) with business significance as the primary key.

But for most of the time, the physical storage space added by this field is actually very small and not as scary as many people think. And the logical simplicity is considerable.

In addition, whether to choose the self-increment type as the primary key, it can be said that each has its own advantages. if you use self-increment, the application can not care the primary key is worth setting, but there is a risk of becoming a bottleneck under high concurrency, of course, if concurrency is not very high, it generally will not become a bottleneck. If you control the primary key value yourself, you need to pay a little bit more to generate this value, and the concurrency problem can be solved by expanding the application cluster.

The above is all the contents of mysql's self-increasing method for setting fields. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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

Database

Wechat

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

12
Report