Loading

MySQL AUTO INCREMENT

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 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);

Share with:


Leave a Reply

Connect with:





z35W7z4v9z8w