错误 1064 (42000):在零填充列中出现 SQL 语法错误?


以下是错误,当您错误地实现 ZEROFILL 时会出现该错误。

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

若要正确实现,请使用以下语法:

语法

yourColumnName int(10) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY

首先,让我们创建一个表:

mysql> create table DemoTable
   -> (
   -> StudentCode int(10) ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY
   -> );
Query OK, 0 rows affected (0.55 sec)

使用 insert 命令在表中插入一些记录:

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)

使用 select 语句从表中显示所有记录:

mysql> select *from DemoTable;

这将产生以下输出:

+-------------+
| StudentCode |
+-------------+
| 0000000001  |
| 0000000002  |
| 0000000003  |
| 0000000004  |
| 0000000005  |
+-------------+
5 rows in set (0.00 sec)

更新于:2019-12-13

533 次浏览

开启你的 职业生涯

通过完成课程获取认证

开始吧
广告
© . All rights reserved.