在 MySQL 中使用 ZEROFILL 设置自定义自动增量
mysqlmysqli database更新于 2024/10/12 15:40:17
首先让我们创建一个表。在这里。我们已使用 ZEROFILL 和 AUTO_INCREMENT 设置 UserId 列
mysql> create table DemoTable1831 ( UserId int(7) zerofill auto_increment, PRIMARY KEY(UserId) ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1831 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1831 values(); Query OK, 1 row affected (0.00 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1831;
这将产生以下输出。所有值均对 UserId 字段宽度 7 进行零填充
+---------+ | UserId | +---------+ | 0000101 | | 0000102 | | 0000103 | | 0000104 | +---------+ 4 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

