本文主要是介绍Mysql中的AUTO_INCREMENT,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
AUTO_INCREMENT
MySQL中最简单使用序列的方法就是使用 MySQL AUTO_INCREMENT 来定义列。
实例
以下实例中创建了数据表insect, insect中id无需指定值可实现自动增长。
mysql> CREATE TABLE insect-> (-> id INT UNSIGNED NOT NULL AUTO_INCREMENT,-> PRIMARY KEY (id),-> name VARCHAR(30) NOT NULL, # type of insect-> date DATE NOT NULL, # date collected-> origin VARCHAR(30) NOT NULL # where collected ); Query OK, 0 rows affected (0.02 sec) mysql> INSERT INTO insect (id,name,date,origin) VALUES-> (NULL,'housefly','2001-09-10','kitchen'),-> (NULL,'millipede','2001-09-10','driveway'),-> (NULL,'grasshopper','2001-09-10','front yard'); Query OK, 3 rows affected (0.02 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM insect ORDER BY id; +----+-------------+------------+------------+ | id | name | date | origin | +----+-------------+------------+------------+ | 1 | housefly | 2001-09-10 | kitchen | | 2 | millipede | 2001-09-10 | driveway | | 3 | grasshopper | 2001-09-10 | front yard | +----+-------------+------------+------------+ 3 rows in set (0.00 sec)
这篇关于Mysql中的AUTO_INCREMENT的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!