MySQL 错误 #1064

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2706498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:52:58  来源:igfitidea点击:

MySQl Error #1064

mysqlmysql-error-1064

提问by Anthony

I keep getting this error:

我不断收到此错误:

MySQL said: #1064 - 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 'INSERT INTO books.book(isbn10,isbn13,title,edition,author_f_name,author_m_na' at line 15

MySQL 说:#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 15 行的“INSERT INTO books.book(isbn10,isbn13,title,edition,author_f_name,author_m_na”附近使用的正确语法

with this query:

使用此查询:

USE books;

DROP TABLE IF EXISTS book;


    CREATE TABLE `books`.`book`(
    `book_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `isbn10` VARCHAR(15) NOT NULL,
    `isbn13` VARCHAR(15) NOT NULL,
    `title` VARCHAR(50) NOT NULL,
    `edition` VARCHAR(50) NOT NULL,
    `author_f_name` VARCHAR(50) NOT NULL,
    `author_m_name` VARCHAR(50) NOT NULL,
    `author_l_name` VARCHAR(50) NOT NULL,
    `cond` ENUM('as new','very good','good','fair','poor') NOT NULL,
    `price` DECIMAL(8,2) NOT NULL,
    `genre` VARCHAR(50) NOT NULL,
    `quantity` INT NOT NULL)

    INSERT INTO books.book(isbn10,isbn13,title,edition,author_f_name,author_m_name,author_l_name,cond,price,genre,quantity)** 
    VALUES ('0136061699','978-0136061694','Software Engineering: Theory and Practice','4','Shari','Lawrence','Pfleeger','very good','50','Computing','2');

Any idea what the problem is?

知道问题是什么吗?

回答by Puaka

maybe you forgot to add ";" after this line of code:

也许你忘了;在这行代码后添加“ ”:

`quantity` INT NOT NULL)

回答by KK2019

In my case I was having the same error and later I come to know that the 'condition' is mysql reserved keyword and I used that as field name.

就我而言,我遇到了同样的错误,后来我知道“条件”是 mysql 保留关键字,我将其用作字段名称。

回答by Joseph Rex

Sometimes when your table has a similar name to the database name you should use back tick. so instead of:

有时,当您的表名称与数据库名称相似时,您应该使用反勾号。所以而不是:

INSERT INTO books.book(field1, field2) VALUES ('value1', 'value2');

You should have this:

你应该有这个:

INSERT INTO `books`.`book`(`field1`, `field2`) VALUES ('value1', 'value2');

回答by Exp3rt

At first you need to add semi colon (;) after quantity INT NOT NULL)then remove ** from ,genre,quantity)**. to insert a value with numeric data type like int, decimal, float, etc you don't need to add single quote.

首先你需要添加分号 (;)quantity INT NOT NULL)然后从,genre,quantity)**. 要插入具有数字数据类型(如 int、decimal、float 等)的值,您无需添加单引号。