Nov 10, 2018

What is auto increment in MySQL

What is auto increment?

Auto Increment is a function that operates on numeric data types. It automatically generates sequential numeric values every time that a record is inserted into a table for a field defined as auto increment.

  • Auto increment attribute when specified on a column with a numeric data types, generates numbers sequentially whenever a new row is added into the database.
  • The Auto increment is commonly used to generate primary keys.
  • The defined data type on the Auto increment should be large enough to accommodate many records. 
  • It is considered a good practice to specify the unsigned constraint on auto increment primary keys to avoid having negative numbers.
  • When a row is deleted from a table, its auto incremented id is not re-used. MySQL continues generating new numbers sequentially.
  • By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record
  • To let AUTO_INCREMENT sequence start with another value , use AUTO_INCREMENT = 10