This example illustrates how to define AUTO_INCREMENT of a field.
This example illustrates how to define AUTO_INCREMENT of a field.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 | +----+--------------------------------+
|