Home Tutorial Php Sql MySQL Auto_Increment

 
 

Share on Google+Share on Google+
MySQL Auto_Increment
Posted on: December 9, 2010 at 12:00 AM
Advertisement
This example illustrates how to define AUTO_INCREMENT of a field.

MySQL Auto_Increment

This example illustrates how to define AUTO_INCREMENT of a field.

The AUTO_INCREMENT attribute can be used to generate a unique identity. Here we make PRIMARY KEY to the id.

 

 

Query

 

CREATE TABLE animals (
      id MEDIUMINT NOT NULL AUTO_INCREMENT,
      name CHAR(30) NOT NULL,
      PRIMARY KEY (id)
  );

 

Query

 

INSERT INTO animals (name) VALUES
     ('dog'),('cat'),('penguin'),
     ('lax'),('whale'),('ostrich');

 

Query

 

SELECT * FROM animals;

 

Output

 

+----+--------------------------------+
| id | name                           |
+----+--------------------------------+
| 1  | dog                            |
| 2  | cat                            |
| 3  | penguin                        |
| 4  | lax                            |
| 5  | whale                          |
| 6  | ostrich                        |
+----+--------------------------------+

 

Advertisement

Related Tags for MySQL Auto_Increment:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com