MySQL AUTO INCREMENT constraint is used for sequentially automatically generating numeric values every time a record is inserted into a table. AUTOINCREMENT allows unique value. Often, we use AUTOINCREMENT with PRIMARY KEY constraints.
MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.
Example:-
CREATE TABLE Employee(
ID int AUTO_INCREMENT PRIMARY KEY,
ename varchar(255),
emailid varchar(255),
ephone varchar(15),
ecity varchar(25),
UNIQUE KEY unique_email (emailid)
);
By default, AUTOINCREMENT starts from 1. But if we define the start AUTOINCREMENT value then AUTOINCREMENT will start from there:-
Example:-
ALTER TABLE employee AUTO_INCREMENT=50;
If we define AUTOINCREMENTÂ for ID then when we INSERT any value, then no need to define any value for ID.
Example:-
INSERT INTO employee (ename, emailid, ephone, ecity)
VALUES (Raj Singh,’raj@test.com’, 9957231323, Sira);
Read Also:-
PRIMARY KEY CONSTRAINT
FOREIGN KEY CONSTRAINT
UNIQUE CONSTRAINT
CHECK CONSTRAINT
NOT NULL CONSTRAINT
DEFAULT CONSTRAINT
CREATE INDEX CONSTRAINT
INDEX CONSTRAINT
ENUM CONSTRAINT
For more detail about MySQL constraints please follow here
good explanation about mysql auto-increment.