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服务器版本相对应的手册,以在第1行的'condition VARCHAR(50)NOT NULL,date_of_diagnosis DATE,treatment TEXT,pssn INT'附近使用正确的语法
最佳答案
条件是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));
关于mysql - 语法有什么问题?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15955579/