用 ZEROFILL 在 MySQL 中設定自定義自動增量


讓我們先建立一個表。此處,我們設定 UserId 列為 ZEROFILL 和 AUTO_INCREMENT

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 的 zerofill

+---------+
| UserId  |
+---------+
| 0000101 |
| 0000102 |
| 0000103 |
| 0000104 |
+---------+
4 rows in set (0.00 sec)

更新於:2019-12-24

668 次瀏覽

開啟你的 職業生涯

完成課程並獲得認證

入門
廣告
© . All rights reserved.