Tuesday, 6 November 2018

Mysql: How to set AUTO_INCREMENT step

How to set AUTO_INCREMENT step
The AUTO_INCREMENT attribute is used to generate a unique value for an identity column.
Let us check how it works:
As you can see id values were generated from 1 to 4 with step 1. To control AUTO_INCREMENT operation we can use server variables – auto_increment_increment  And auto_increment_offset.
  • auto_increment_increment – is the incremental value, controls the interval between successive column values.
  • auto_increment_offset – determines the starting value for the AUTO_INCREMENT field; this value is used for the first record inserted into the table.
These variables have session and global scope.
Let us try to use these variables –
The first records has id = 5, next id is 15 and so on.

0 comments:

Post a Comment