尝试使用两个外键创建一个表并继续收到此错误:
#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)
);
任何人的见解?
答案 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)
);