H I O X INDIA
MySQL Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 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
Feedback





Insert Auto Increment Field into a 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)


others


        MySQL is the most popular open source database Management system. 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-2005 HIOX INDIA - hioxindia.com

Other Links