Using
AUTO_INCREMENT
The AUTO_INCREMENT
attribute can be used to generate a unique identity for new rows:
CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM; INSERT INTO animals (name) VALUES ('dog'),('cat'),('penguin'), ('lax'),('whale'),('ostrich'); SELECT * FROM animals;
Which returns:
+----+---------+ | id | name | +----+---------+ | 1 | dog | | 2 | cat | | 3 | penguin | | 4 | lax | | 5 | whale | | 6 | ostrich | +----+---------+
'IT' 카테고리의 다른 글
Tim Cook email to Apple employees: "Apple is not going to change" (0) | 2011.08.27 |
---|---|
Workarounds Issued For 'Apache Killer' Attack (0) | 2011.08.27 |
Calculating Visits Per Day (0) | 2011.08.26 |
Using User-Defined Variables (0) | 2011.08.26 |
Getting Information About Databases and Tables (0) | 2011.08.26 |