|
Auto Increment :
The 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
Now if we select the table, the field name id will be automatically incremented as shown below.
mysql> select * from stud;
+----+---------+
| id | name |
+----+---------+
| 1 | anne |
| 2 | michael |
| 3 | james |
| 4 | rajesh |
| 5 | harry |
+----+---------+
5 rows in set (0.00 sec)
|