#1064 - 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在附近使用正确的语法

时间:2014-06-26 19:23:13

标签: mysql sql jdbc xampp

你好我是sql的新手,只是真正用于JDBC,我试图创建一个数据库调用SuperMarket并用这个sql脚本创建表

CREATE TABLE item (
ID INT NOT NULL CONSTRAINT pk_item PRIMARY KEY,
name VARCHAR(30),
price DOUBLE PRECISION,
quantity INT
);

CREATE TABLE customer (
ID INT NOT NULL CONSTRAINT pk_customer PRIMARY KEY,
name VARCHAR(30)
);

CREATE TABLE employee (
ID INT NOT NULL CONSTRAINT pk_employee PRIMARY KEY,
name VARCHAR(30),
password VARCHAR(15)
);

CREATE TABLE trans (
ID INT NOT NULL CONSTRAINT pk_transaction PRIMARY KEY,
employee INT,
customer INT,
is_open INT
);

CREATE TABLE acquisition (
ID INT NOT NULL CONSTRAINT pk_acquisition PRIMARY KEY,
trans INT,
item INT,
quantity INT
);

当我尝试使用xampp在phpMyAdmin中导入它时,我收到以下错误:

Number 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 'CONSTRAINT pk_item PRIMARY KEY,
name VARCHAR(30),
price DOUBLE PRECISION,
qua' at line 2 

我仍然找不到任何语法错误,任何人都可以告诉我我做错了什么?

1 个答案:

答案 0 :(得分:2)

试试这个:

CREATE TABLE item (
   ID INT NOT NULL,
   name VARCHAR(30),
   price DOUBLE PRECISION,
   quantity INT,

   CONSTRAINT pk_item PRIMARY KEY (ID)
);

您的CONSTRAINT关键字位于错误的位置。其他表也是如此。

如果您只想将ID作为主键,则可以执行以下操作:

CREATE TABLE item (
   ID INT NOT NULL PRIMARY KEY,
   name VARCHAR(30),
   price DOUBLE PRECISION,
   quantity INT
);