|
自动递增 :
自动递增属性用于为插入的记录生成唯一的标识值。关于使用自动递增,请看如下的例子。
mysql> create table stud(id bigint not null unique auto_increment,
name char(20));
Query OK, 0 rows affected (0.03 sec)
在以上的查询中, 我们创建了表stud,并且对字段名称id进行了自动递增。现在我们就可以单独给字段名称添加值,详细如下。
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
现在如果我们选择表,字段名称id将会自动递增,详细如下。
mysql> select * from stud;
+----+---------+
| id | name |
+----+---------+
| 1 | anne |
| 2 | michael |
| 3 | james |
| 4 | rajesh |
| 5 | harry |
+----+---------+
5 rows in set (0.00 sec)
|