Many people have asked how to set an auto-increment field in MySQL. The following describes how to set an auto-increment field in MySQL. I hope you can learn more about the MySQL database.
Related statements for setting auto-increment fields in MySQL:
Alter table album change ALBUM_ID bigint not null auto_increment;
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 int primary key auto_increment;
Note: auto_increment can be used only for int type and primary key.
If hibernate is used as the persistence layer, the identity type is used for the primary key ID.
For the primary key selection of a table, from the perspective of architecture design, it is better to design a business-independent field as the primary key for the system.
Of course, this will inevitably increase the size of the table data. Some people may think this side effect is not worthwhile and choose a field or multiple fields with business significance as the primary key.
But most of the time, the physical storage space added to this field is actually very small, and it is not as terrible as many people think. The logic simplicity is considerable.
In addition, whether to select the auto-increment type as the primary key has its own advantages. If auto-increment is used, the application can ignore the value setting of this primary key, but there is a risk that high concurrency will become a bottleneck. Of course, if the concurrency is not very high, it will not become a bottleneck. If you control this primary key value, you need to pay a little bit to generate this value. The concurrency problem can be solved by extending the application cluster.
The preceding section describes how to set auto-increment fields in MySQL.
Mysql inserts an instance of the Clob Field
Default length of common MySql Fields
MySQL index type
How to Set MySql access restrictions
Six Methods for changing the password of MySQL