MySQL Auto Increment

How to add Auto Increment attribute in MySQL tables ?

Explanation

Auto Increment :


MySQL auto increment attribute is used to generate a unique identity for the inserting rows. Lets see an example using auto increment.
mysql> create table stud(id bigint not null unique auto_increment, name char(20));

Query OK, 0 rows affected (0.03 sec)
In the above query, we have created a table stud and we have assigned autoincrement to the field name id. Now we can insert the values for the field name alone as given in the below query.
mysql> insert into stud(name) values ('anne'),('michael'),('james'), ('rajesh'),('harry');

Query OK, 5 rows affected (0.05 sec) Records: 5 Duplicates: 0 Warnings: 0
After using mysql auto increment attribute if we select the table, the field name id will be automatically incremented as shown below.
MySQL Auto Increment

Ask Questions

Ask Question