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)
);

给出错误:

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“condition VARCHAR(50) NOT NULL, date_of_diagnosis DATE,treatment TEXT, pssn INT”附近使用正确的语法

4

2 回答 2

7

条件是保留字。你必须用反引号括起来:

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));
于 2013-04-11T17:55:57.597 回答
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));
于 2013-04-11T17:58:45.553 回答