MySQL Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback
 





MySQL Auto Increment


Tutorials Mysql

Topic
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> select * from stud;
+----+---------+
| id | name    |
+----+---------+
|  1 | anne    |
|  2 | michael |
|  3 | james   |
|  4 | rajesh  |
|  5 | harry   |
+----+---------+
5 rows in set (0.00 sec)



A Note

MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


Other Links

web hosting