MySQL 表中仅设置一个列为自动增长的插入方式?


我们首先创建一个表:

mysql> create table DemoTable
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT,
   -> PRIMARY KEY(StudentId)
   -> );
Query OK, 0 rows affected (0.60 sec)

使用 insert 命令在表中插入一些记录。在此处,我们插入了一个值,但由于它是自动增长,因此,可以看见默认值:

mysql> insert into DemoTable(StudentId) values(0);
Query OK, 1 row affected (0.18 sec)

使用 select 语句显示表中的所有记录:

mysql> select *from DemoTable;

这将会生成以下输出。默认自动增长值为 1,第一个值可见:

+-----------+
| StudentId |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)

更新日期:2019 年 7 月 30 日

98 浏览

开启你的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.