在建立表時為 AUTO_INCREMENT 設定自定義值並使用 ZEROFILL。現在當不插入任何內容並使用 INSERT 語句時會發生什麼?
我們來看一個例子,建立一個表,其中我們把 StudentId 列設定為 AUTO_INCREMENT = 100 並且還使用了 ZEROFILL -
mysql> create table DemoTable ( StudentId int(7) ZEROFILL NOT NULL AUTO_INCREMENT, PRIMARY KEY(StudentId) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.48 sec)
使用 insert 命令在表中插入一些記錄。現在,當沒有插入任何內容時,值將從 101(自動增量)開始,而由於我們在建立上述表格時設定了 ZEROFILL,因此左側的其餘值將填充為 0 -
mysql> insert into DemoTable values(); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.09 sec)
使用 select 語句從表中顯示所有記錄 -
mysql> select *from DemoTable;
這將生成以下輸出 -
+-----------+ | StudentId | +-----------+ | 0000100 | | 0000101 | | 0000102 | | 0000103 | +-----------+ 4 rows in set (0.00 sec)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP