為什麼以下程式碼在 MySQL 中顯示錯誤:INSERT INTO yourTableName VALUE(yourValue1,yourValue2,.......N);?


錯誤在於 VALUE() 的語法。請使用 VALUES() 而不是 VALUE()。插入查詢的正確語法如下 −

INSERT INTO yourTableName VALUES(yourValue1,yourValue2,.......N);

讓我們首先建立一個表 −

mysql> create table DemoTable
(
   StudentId int,
   StudentName varchar(40),
   StudentAge int
);
Query OK, 0 rows affected (0.48 sec)

使用插入命令在表中插入一些記錄 −

mysql> INSERT INTO DemoTable VALUES(1001,'Tom',20);
Query OK, 1 row affected (0.11 sec)
mysql> INSERT INTO DemoTable VALUES(1002,'Mike',21);
Query OK, 1 row affected (0.13 sec)
mysql> INSERT INTO DemoTable VALUES(1003,'Sam',19);
Query OK, 1 row affected (0.08 sec)

使用 select 語句顯示錶中的所有記錄 −

mysql> select *from DemoTable;

這將產生以下輸出 −

+-----------+-------------+------------+
| StudentId | StudentName | StudentAge |
+-----------+-------------+------------+
| 1001      | Tom         |         20 |
| 1002      | Mike        |         21 |
| 1003      | Sam         |         19 |
+-----------+-------------+------------+
3 rows in set (0.00 sec)

更新於:2019 年 10 月 4 日

126 次瀏覽

開啟您的職業生涯

完成本課程即可獲得認證

立即開始
廣告
© . All rights reserved.