#1064 - 你的SQL语法有错误;查看与MySQL服务器版本对应的手册

时间:2022-05-20 14:53:26

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

以下是我正在使用的一些信息

  1. Server type: MySQL
  2. 服务器类型:MySQL

  3. Server version: 5.5.32 - MySQL Community Server(GPL)
  4. 服务器版本:5.5.32 - MySQL社区服务器(GPL)

  5. phpMyAdmin: 4.0.4.1, latest stable version: 4.1.7
  6. 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?

我花了一天时间把头靠在墙上,现在我觉得是时候寻求帮助。我想知道是否有人能告诉我我做错了什么?

5 个解决方案

#1


7  

Remove the comma

删除逗号

receipt int(10),

And also AUTO INCREMENT should be a KEY

并且AUTO INCREMENT也应该是一个关键

double datatype also requires the precision of decimal places so right syntax is double(10,2)

double数据类型也需要小数位的精度所以正确的语法是double(10,2)

#2


4  

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,

#3


1  

In MySQL, the word 'type' is a Reserved Word.

在MySQL中,“类型”一词是保留字。

#4


0  

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)将使总数为10位,小数点后允许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) );

#5


0  

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:如果不指定主键约束,则无法添加新表[如果以某种方式创建它,则不是一个好习惯]。所以代码:

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 type is something like that is used(commonly used with Join Types). So the code:

规则2:不允许您使用关键字(具有预定义的词)作为字段名称。这里使用类型(通常与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服务器中尝试它)并确保此代码有效。现在从数据库中删除表并执行程序中的代码。谢谢。

#1


7  

Remove the comma

删除逗号

receipt int(10),

And also AUTO INCREMENT should be a KEY

并且AUTO INCREMENT也应该是一个关键

double datatype also requires the precision of decimal places so right syntax is double(10,2)

double数据类型也需要小数位的精度所以正确的语法是double(10,2)

#2


4  

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,

#3


1  

In MySQL, the word 'type' is a Reserved Word.

在MySQL中,“类型”一词是保留字。

#4


0  

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)将使总数为10位,小数点后允许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) );

#5


0  

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:如果不指定主键约束,则无法添加新表[如果以某种方式创建它,则不是一个好习惯]。所以代码:

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 type is something like that is used(commonly used with Join Types). So the code:

规则2:不允许您使用关键字(具有预定义的词)作为字段名称。这里使用类型(通常与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服务器中尝试它)并确保此代码有效。现在从数据库中删除表并执行程序中的代码。谢谢。