Lỗi sau xảy ra khi triển khai ZEROFILL không đúng:
mysql> CREATE TABLE DemoTable ( StudentCode INT(10) NOT NULL ZEROFILL AUTO_INCREMENT PRIMARY KEY ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ZEROFILL AUTO_INCREMENT PRIMARY KEY )' at line 3
Cú pháp đúng:
Cú pháp
tenCot INT(10) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY
Tạo bảng đúng:
mysql> CREATE TABLE DemoTable ( StudentCode INT(10) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.55 sec)
Chèn bản ghi:
mysql> INSERT INTO DemoTable VALUES(); Query OK, 1 row affected (0.21 sec) mysql> INSERT INTO DemoTable VALUES(); Query OK, 1 row affected (0.11 sec) mysql> INSERT INTO DemoTable VALUES(); Query OK, 1 row affected (0.28 sec) mysql> INSERT INTO DemoTable VALUES(); Query OK, 1 row affected (0.10 sec) mysql> INSERT INTO DemoTable VALUES(); Query OK, 1 row affected (0.10 sec)
Hiển thị:
mysql> SELECT * FROM DemoTable;
Kết quả (có padding 0):
+-------------+ | StudentCode | +-------------+ | 0000000001 | | 0000000002 | | 0000000003 | | 0000000004 | | 0000000005 | +-------------+ 5 rows in set (0.00 sec)