CREATE TABLE Existing_medical_condition (
condition VARCHAR(50) NOT NULL,
date_of_diagnosis DATE, treatment TEXT,
pssn INT NOT NULL,
CONSTRAINT emc_key PRIMARY KEY(condition, pssn),
FOREIGN KEY(pssn) REFERENCES Patient(ssn)
);
给出错误:
错误1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在'条件VARCHAR(50)NOT NULL,date_of_diagnosis DATE,处理TEXT,pssn INT'第1行附近使用正确的语法
答案 0 :(得分:7)
条件是reserved word。你必须用反引号包住它:
CREATE TABLE Existing_medical_condition (
`condition` VARCHAR(50) NOT NULL,
date_of_diagnosis DATE,
treatment TEXT,
pssn INT NOT NULL,
CONSTRAINT emc_key
PRIMARY KEY(condition, pssn),
FOREIGN KEY(pssn) REFERENCES Patient(ssn));
答案 1 :(得分:0)
尽量避免列名的保留关键字。如果你还想要,你可以写下面。
CREATE TABLE Existing_medical_condition ([condition] VARCHAR(50) NOT NULL, date_of_diagnosis DATE, treatment TEXT,
pssn INT NOT NULL, CONSTRAINT emc_key PRIMARY KEY(condition, pssn), FOREIGN KEY(pssn) REFERENCES Patient(ssn));