为什么以下内容在MySQL中显示错误:INSERT INTO yourTableName VALUE(yourValue1,yourValue2,.... N);?
错误在于VALUE()
.UseVALUES()
而不是的语法中VALUE()
。插入查询的正确语法如下-
INSERT INTO yourTableName VALUES(yourValue1,yourValue2,.......N);
让我们首先创建一个表-
mysql> create table DemoTable ( StudentId int, StudentName varchar(40), StudentAge int );
使用插入命令在表中插入一些记录-
mysql> INSERT INTO DemoTable VALUES(1001,'Tom',20); mysql> INSERT INTO DemoTable VALUES(1002,'Mike',21); mysql> INSERT INTO DemoTable VALUES(1003,'Sam',19);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+-------------+------------+ | StudentId | StudentName | StudentAge | +-----------+-------------+------------+ | 1001 | Tom | 20 | | 1002 | Mike | 21 | | 1003 | Sam | 19 | +-----------+-------------+------------+ 3 rows in set (0.00 sec)