You can use composite indexes to create multiple, independent, self-increment sequences in the same data table by creating a primary KEY OR unique index that consists of multiple data columns for the datasheet and auto_ The Increment data column is included in this index as its last data column. Thus, in this composite index, each of the preceding columns of data constitutes a unique combination, and the Auto_increment data column at the end produces a sequence number corresponding to that combination.
We often use a unique number to identify the record. The Auto_increment property of the data column can be automatically generated in MySQL. MySQL supports a variety of data tables, each of which has a different self-increment property, which describes the data column self-increment properties in various tables.
1 Usage:
CREATE TABLE Test
(
ID INT UNSIGNED not NULL PRIMARY KEY auto_increment,
Username VARCHAR () not NULL
) auto_increment = 100;
You can use the "auto_increment=n" option to specify a self-increment initial value when building a table.
Use the ALTER TABLE TABLE_NAME AUTO_INCREMENT=N command to reset the starting value of the increment.
Description
(1) If you insert a null into a auto_increment data column, MySQL will automatically generate the next serial number. Numbering starts at 1, and 1 increments by cardinality.
(2) inserting 0 into the auto_increment data column has the same effect as inserting a null value. However, it is not recommended to do this, or to insert a null value as well.
(3) when inserting a record, the value is not explicitly specified for auto_increment, which is equivalent to inserting a null value.
(4) When inserting a record, if a numeric value is explicitly specified for the Auto_increment data column, there are two cases where an error message occurs if the inserted value repeats with an existing number because the value of the Auto_increment data column must be unique; In case two, If the inserted value is greater than the numbered value, it is inserted into the data column and the next number is incremented from the new value. In other words, you can skip some numbers.
(5) If the self-increment column is updated with the update command, an error occurs if the column value repeats with the existing value. If it is greater than the existing value, the next number increments from that value.
About MySQL Auto_increment