MySQL错误1064创建表

时间:2015-01-21 13:02:20

标签: mysql sql mysql-error-1064

尝试使用两个外键创建一个表并继续收到此错误:

#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 'idbed MEDIUMINT UNSIGNED NOT NULL,
idnumber MEDIUMINT UNSIGNED NOT NULL,' at line 2

表格是:

CREATE TABLE care(
idbed MEDIUMINT UNSIGNED NOT NULL,
idnumber MEDIUMINT UNSIGNED NOT NULL,
PRIMARY KEY(idbed, idnumber),
FOREIGN KEY(idbed) REFERENCES intensivecarebed(idbed)
FOREIGN KEY(idnumber) REFERENCES employee(idnumber));

其他两个表是:

CREATE TABLE Employee(
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
address VARCHAR(60) NOT NULL,
salary FLOAT UNSIGNED NOT NULL,
specialization VARCHAR(50) NOT NULL<
clinic_name VARCHAR(50) NOT NULL,
PRIMARY KEY(idnumber)
);

CREATE TABLE intensivecarebed(
idbed MEDIUMINT UNSIGNED NOT NULL,
clinic_name VARCHAR(50) NOT NULL,
tax_reg_number TINYINT(10) UNSIGNED NOT NULL,
PRIMARY KEY(idbed)
);

任何人的见解?

1 个答案:

答案 0 :(得分:2)

您的代码中存在多个错误:

  • 您错过了idnumber表格中的Employee
  • 你错过了外键之间的昏迷。
  • 您有<而不是,

在创建其他两个表之后,您还必须创建care表,因为您指的是这些表。

试试这个:

CREATE TABLE Employee(
    idnumber MEDIUMINT UNSIGNED NOT NULL,
    first_name VARCHAR(30) NOT NULL,
    last_name VARCHAR(30) NOT NULL,
    address VARCHAR(60) NOT NULL,
    salary FLOAT UNSIGNED NOT NULL,
    specialization VARCHAR(50) NOT NULL,
    clinic_name VARCHAR(50) NOT NULL,
    PRIMARY KEY(idnumber)
);

CREATE TABLE intensivecarebed(
    idbed MEDIUMINT UNSIGNED NOT NULL,
    clinic_name VARCHAR(50) NOT NULL,
    tax_reg_number TINYINT(10) UNSIGNED NOT NULL,
    PRIMARY KEY(idbed)
);

CREATE TABLE care(
    idbed MEDIUMINT UNSIGNED NOT NULL,
    idnumber MEDIUMINT UNSIGNED NOT NULL,
    PRIMARY KEY(idbed, idnumber),
    FOREIGN KEY(idbed) REFERENCES intensivecarebed(idbed),
    FOREIGN KEY(idnumber) REFERENCES employee(idnumber)
);