簡體   English   中英

錯誤1064(42000):您的SQL語法有錯誤; 我找不到我做錯了

[英]ERROR 1064 (42000): You have an error in your SQL syntax; I can't find that I did wrong

mysql> DESC transaction;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| title | varchar(100) | NO   |     | NULL    |                |
| from  | int(11)      | NO   |     | NULL    |                |
| to    | int(11)      | NO   |     | NULL    |                |
| cost  | int(11)      | NO   |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql> INSERT INTO transaction (title, from, to, cost) VALUES ('Ham', 1, 4, 9000);
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 'from, to, cost) VA
LUES ('Ham', 1, 4, 9000)' at line 1

我試圖將數據插入“交易”表。 我認為查詢很好,但是卻說錯誤。 我怎么了 請幫我!

  • 避免將保留關鍵字用作列名。
  • 仍然,如果需要使用它們,請在引用它們時使用雙引號。 在編寫select語句時也會出現語法錯誤。 不要忘了使用雙引號

采用:

select "from", cost from... 

代替:

select from, cost from...

將Tsql插入到:

INSERT INTO `transaction` (`title`, `from`, `to`, `cost`) VALUES ('Ham', 1, 4, 9000);

在MySQL中,某些詞(例如SELECT,INSERT,FROM等)是保留詞。 由於它們具有特殊含義,因此每當您將它們用作表名,列名或其他類型的標識符時,MySQL都會將其視為語法錯誤-除非您用反引號將標識符引起來。

有關更多詳細信息,請參見https://dev.mysql.com/doc/refman/5.7/en/keywords.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM