在 MySQL 表中插入仅一列设置为 auto_increment?
mysqlmysqli database更新于 2025/9/2 18:52:17
首先我们创建一个表 −
mysql> create table DemoTable -> ( -> StudentId int NOT NULL AUTO_INCREMENT, -> PRIMARY KEY(StudentId) -> ); Query OK, 0 rows affected (0.60 sec)
使用 insert 命令在表中插入一些记录。这里我们插入了一个值,但由于它是 AUTO_INCREMENT,因此默认值是可见的 −
mysql> insert into DemoTable(StudentId) values(0); Query OK, 1 row affected (0.18 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出。默认的 AUTO_INCREMENT 值 1 作为第一个值是可见的 −
+-----------+ | StudentId | +-----------+ | 1 | +-----------+ 1 row in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

