Understanding AUTO_INCREMENT in MySQL
AUTO_INCREMENT is a feature in MySQL that automatically generates sequential numeric values for a column whenever a new row is inserted. It is commonly used with primary keys to ensure each row gets a unique identifier without manual input.
The column starts at a default value (usually 1) and increases by 1 for each new row.
It removes the need to manually provide a unique ID for every insert.
MySQL keeps track of the next value internally.
AUTO_INCREMENT can only be applied to numeric types (INT, BIGINT, etc.).
AUTO_INCREMENT is most often used on the PRIMARY KEY column.
The primary key ensures that each generated value is unique.
Although typically used with PRIMARY KEY, AUTO_INCREMENT can also work with UNIQUE keys.
A table can have only one AUTO_INCREMENT column.
In this example, MySQL automatically assigns a new, incrementing ID each time a row is inserted. This ensures simple, reliable, and unique row identification.