H I O X INDIA
MySQL Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
More about Mysql
Feedback




Insert Auto Increment Field into a Database Table


Topic

How to add an autoincrement field with MySQL?
Auto Increment using Insert statement



Explanation

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)





        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.


privacy policy     license     sitemap
© 2004-2009 HIOX INDIA - hioxindia.com

Other Links