用 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)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
JAVA
iOS
HTML
CSS
安卓
python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP