且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL 将前导数字添加到列中的现有 ID

更新时间:2023-11-30 20:27:10

在栏目上声明ZEROFILL:

mysql> create table foobar (nr integer(4) ZEROFILL);
Query OK, 0 rows affected (0.31 sec)

mysql> INSERT INTO foobar VALUES (1),(12),(123),(1234),(12345);
Query OK, 5 rows affected (0.05 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT * FROM foobar;
|  0001 
|  0012 
|  0123 
|  1234 
| 12345