#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21798464/
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
#1064 -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
提问by tsjr63
I'm new to PHP
and MySQL
and ran into a little trouble with a learning project I'm working on.
我是新手PHP
,MySQL
并且在我正在进行的学习项目中遇到了一些麻烦。
Whenever I try to create a table
每当我尝试创建表格时
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
)
I get the following error message:
我收到以下错误消息:
#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 ') NOT NULL, type varchar(6) NOT NULL, notes varchar(512), receipt int(10), ' at line 6**
#1064 - 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 ') NOT NULL 附近使用的正确语法,键入 varchar(6) NOT NULL,注意 varchar(512),收据 int(10),' 在第 6 行**
Here is some info on what I'm working with
这是有关我正在使用的内容的一些信息
- Server type: MySQL
- Server version: 5.5.32 - MySQL Community Server(GPL)
- phpMyAdmin: 4.0.4.1, latest stable version: 4.1.7
- 服务器类型:MySQL
- 服务器版本:5.5.32 - MySQL 社区服务器(GPL)
- phpMyAdmin:4.0.4.1,最新稳定版:4.1.7
I've spent a day knocking my head against the wall over this and now I think its time to ask for help.I was wondering if anyone can tell me what I'm doing wrong?
我已经花了一天的时间来解决这个问题,现在我想是时候寻求帮助了。我想知道是否有人能告诉我我做错了什么?
回答by G one
Remove the comma
去掉逗号
receipt int(10),
receipt int(10),
And also AUTO INCREMENT
should be a KEY
而且也AUTO INCREMENT
应该是KEY
double
datatype also requires the precision of decimal places so right syntax is double(10,2)
double
数据类型还需要小数位的精度,所以正确的语法是 double(10,2)
回答by Ahmed Salman Tahir
One obvious thing is that you will have to remove the comma here
一件显而易见的事情是您必须在此处删除逗号
receipt int(10),
but the actual problem is because of the line
但实际问题是因为线路
amount double(10) NOT NULL,
change it to
将其更改为
amount double NOT NULL,
回答by ak-SE
In MySQL, the word 'type' is a Reserved Word.
在 MySQL 中,“type”这个词是一个保留字。
回答by Ataboy Josef
Rule 1: You can not add a new table without specifying the primary key
constraint[not a good practice if you create it somehow].
So the code:
规则 1:你不能在没有指定primary key
约束的情况下添加新表[如果你以某种方式创建它不是一个好习惯]。所以代码:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Rule 2: You are not allowed to use the keywords(words with predefined meaning) as a field name. Here typeis something like that is used(commonly used with Join Types). So the code:
规则 2:不允许使用关键字(具有预定义含义的词)作为字段名称。这里的type是类似的东西(通常与Join Types 一起使用)。所以代码:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
transaction_type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id));
Now you please try with this code. First check it in your database user interface(I am running HeidiSQL, or you can try it in your xampp/wamp server also)and make sure this code works. Now delete the table from your db and execute the code in your program. Thank You.
现在请尝试使用此代码。首先在您的数据库用户界面中检查它(我正在运行 HeidiSQL,或者您也可以在您的 xampp/wamp 服务器中尝试它)并确保此代码有效。现在从您的数据库中删除该表并在您的程序中执行代码。谢谢你。
回答by oxtub
I see two problems:
我看到两个问题:
DOUBLE(10) precision definitions need a total number of digits, as well as a total number of digits after the decimal:
DOUBLE(10) 精度定义需要总位数,以及小数点后的总位数:
DOUBLE(10,8) would make be ten total digits, with 8 allowed after the decimal.
DOUBLE(10,8) 将是十位总位数,小数点后允许有 8 位。
Also, you'll need to specify your id column as a key :
此外,您需要将 id 列指定为键:
CREATE TABLE transactions(
id int NOT NULL AUTO_INCREMENT,
location varchar(50) NOT NULL,
description varchar(50) NOT NULL,
category varchar(50) NOT NULL,
amount double(10,9) NOT NULL,
type varchar(6) NOT NULL,
notes varchar(512),
receipt int(10),
PRIMARY KEY(id) );