解决使用 varchar(未给出大小)后发生的错误 1064 (42000)
让我们首先看看这种情况何时可能发生。创建一个带有数据类型但没有大小的表并设置列名-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar, LastName varchar ); 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 ', LastName varchar )' at line 4
您可以通过为 varchar 数据类型提供一个大小,比如 varchar(100)来修正以上错误。这样可以解决这个问题。
让我们修复此问题,首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.60 sec)
使用插入命令向表中插入一些记录-
mysql> insert into DemoTable(FirstName,LastName) values('Adam','Smith'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FirstName,LastName) values('John','Doe'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable(FirstName,LastName) values('Chris','Brown'); Query OK, 1 row affected (0.11 sec)
使用 select 语句从表中显示所有记录-
mysql> select *from DemoTable;
这样将输出以下内容-
+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1 | Adam | Smith | | 2 | John | Doe | | 3 | Chris | Brown | +----+-----------+----------+ 3 rows in set (0.00 sec)
广告