AUTO_INCREMENT is a column attribute, primarily used in MySQL and MariaDB, that tells the database engine to assign the next available integer to the column whenever a new row is inserted. The counter starts at 1 (unless overridden) and increases by 1 with each insert. The generated value is guaranteed to be unique within the table and is returned to the client so it can be referenced immediately.Behind the scenes the engine maintains an internal counter, persisted even after restarts. You can retrieve the most recent value with LAST_INSERT_ID().Caveats:- Only one AUTO_INCREMENT column is allowed per table and it must be indexed (commonly PRIMARY KEY).- Gaps appear if a transaction rolls back after reserving a number.- The attribute works only on integer types (TINYINT, SMALLINT, INT, BIGINT) and cannot be combined with NULL default.- In replication, improper handling of offsets can cause collisions.Other dialects implement the same idea differently: PostgreSQL uses SERIAL or IDENTITY, SQL Server uses IDENTITY, and Oracle uses IDENTITY or sequences with triggers.
SERIAL, IDENTITY, PRIMARY KEY, UNIQUE, SEQUENCE, LAST_INSERT_ID
MySQL 3.23 (1998)
It auto-generates a unique integer for the column on every insert, removing the need to specify the value manually.
Exactly one. It must be indexed and is typically declared as the primary key.
Use ALTER TABLE table_name AUTO_INCREMENT = new_start_value; The next insert will use this value.
No, unless the counter is manually reset to a previous value or it overflows the data type size.