Set the primary key to self-increment. The initial value starts at 10 and increases by 10 at a time.

Why did it start at 11? An extra 1.

has been added.

CREATE TABLE mytest13
(
id INT PRIMARY KEY AUTO_INCREMENT,
age VARCHAR (10)
) AUTO_INCREMENT=9;
SET auto_increment_increment=10;
INSERT INTO mytest13 (age) VALUES ("20");
INSERT INTO mytest13 (age) VALUES (" 15");

clipboard.png

Jan.30,2022

you start at 10, 10 is already a value, it is incremented on 10, and the first piece of data is + 1 = 11

.

1, the self-increment of auto_increment_increment, the interval between the next and the previous one is 10, that is, 11-> 21-> 31-> 41, and so on
2, auto_increment_offset: drift value, that is, step size

The essential logic of

is auto_increment_offset + N auto_increment_increment N, which is calculated from 0 to

.

because the self-growing primary key is a sequence of auto_increment_offset + n * auto-increment-increment , auto_increment_offset defaults to 1, so the self-growing value is 1 , 11 , 21 , 31 .
because you set auto_increment=10 , the next self-increment id is 11 <

Let's verify:

I have created the same table. The current auto_increment is 14 , and the maximum id is 13

.

clipboard.png

id id 23, 24 21

clipboard.png

, id auto_increment_offset + n * auto-increment-increment


11011


1010

auto_increment_%

clipboard.png

@eason_li :

auto_increment_increment:
auto_increment_offset:

CREATE TABLESET auto_increment_increment=10;

clipboard.png
that is, the initial value is still 1, but each time it increments to 10. That's not what someone said above, starting with 10, and then + 1

.

2. The calculation of self-increment values is always like this, which is correct

.
auto_increment_offset + N auto_increment_increment

but as a result of changing one of the variables, the range of N becomes [1, 1, 2, 3.] The positive integer
in the

refers to the official MySQL document

.
If either of these variables is changed, and then new rows inserted into a table containing an AUTO_INCREMENT column, the results may seem counterintuitive because the series of AUTO_INCREMENT values is calculated without regard to any values already present in the column, and the next value inserted is the least value in the series that is greater than the maximum existing value in the AUTO_INCREMENT column. The series is calculated like this:
auto_increment_offset + N auto_increment_increment
where N is a positive integer value in the series [1,2,3,.]

combined with the variable values found in one, the value sequence of the self-increment column should be like this [11 code 21]. Because the create table is followed by a AUTO_INCREMENT=9; , then the current insert value of the self-increment column should be greater than 9, but it is the smallest in the sequence of self-increment values, that is, 11.
(for example, if AUTO_INCREMENT=19, is defined in create table, it should be greater than 19, and the minimum value is 21)

Portal

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5cec2-44e79.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5cec2-44e79.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?