让我们首先看看何时会出现这种情况。创建一个表并设置具有数据类型但没有大小的列名-
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))的大小来纠正上述错误。同样可以解决该问题。
让我们修复它,首先创建一个表-
create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100), LastName varchar(100) );
使用插入命令在表中插入一些记录-
insert into DemoTable(FirstName,LastName) values('Adam','Smith'); insert into DemoTable(FirstName,LastName) values('John','Doe'); insert into DemoTable(FirstName,LastName) values('Chris','Brown');
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1 | Adam | Smith | | 2 | John | Doe | | 3 | Chris | Brown | +----+-----------+----------+ 3 rows in set (0.00 sec)