由于错误,SQL create table无法正常工作

时间:2018-04-02 18:08:50

标签: mysql sql phpmyadmin

CREATE TABLE Patient(
pAdminNumber int NOT NULL,
dID int NOT NULL,
wID int NOT NULL,
pName VARCHAR(50),
DOB DATE,
pGender CHAR(10),
pAddress VARCHAR(50),
pTelephone VARCHAR(50),
PRIMARY KEY(pAdminNumber),
FOREIGN KEY(dID)
REFERNCES Doctor(dID),
FOREIGN KEY(wID)
REFERNECES Ward(wID)
);

我正在尝试运行此sql代码,但它不断出错。我跑的其他两个成功执行。

CREATE TABLE Doctor(
dID int NOT NULL,
wID int NOT NULL,
dName VARCHAR(50),
DOB DATE,
dYearsWorked int,
PRIMARY KEY(dID),
FOREIGN KEY(wID)
REFERENCES Ward(wID)
);

CREATE TABLE Ward(
wID int NOT NULL,
wName VARCHAR(50),
PRIMARY KEY (wID) 
);

4 个答案:

答案 0 :(得分:1)

这是一个猜测

CREATE TABLE Patient(
pAdminNumber int NOT NULL,
dID int NOT NULL,
wID int NOT NULL,
pName VARCHAR(50),
DOB DATE,
pGender CHAR(10),
pAddress VARCHAR(50),
pTelephone VARCHAR(50),
PRIMARY KEY(pAdminNumber),
FOREIGN KEY(dID)
REFERENCES Doctor(dID),
FOREIGN KEY(wID)
REFERENCES Ward(wID)
);

检查你的拼写:REFERENCES

答案 1 :(得分:1)

在患者的外键上,REFERENCES被误导为'REFERNCES',应该是:

CREATE TABLE Patient
    ( pAdminNumber int NOT NULL, 
      dID int NOT NULL, 
      wID int NOT NULL, 
      pName VARCHAR(50), 
      DOB DATE, 
      pGender CHAR(10), 
      pAddress VARCHAR(50), 
      pTelephone VARCHAR(50), 
      PRIMARY KEY(pAdminNumber), 
      FOREIGN KEY(dID) REFERENCES Doctor(dID), 
      FOREIGN KEY(wID) REFERENCES Ward(wID) 
    );

答案 2 :(得分:0)

检查拼写的REFERENCES关键字,我相信你拼错了它

CREATE TABLE Ward( wID int NOT NULL, wName VARCHAR(50), 主键(wID) );

CREATE TABLE Doctor( dID int NOT NULL, wID int NOT NULL, dName VARCHAR(50), DOB日期, dYearsWorked int, PRIMARY KEY(dID), 外键(wID) 参考文献Ward(wID) );

CREATE TABLE Patient(pAdminNumber int NOT NULL, dID int NOT NULL, wID int NOT NULL, pName VARCHAR(50), DOB日期, pGender CHAR(10), pAddress VARCHAR(50), pTelephone VARCHAR(50), PRIMARY KEY(pAdminNumber), 外键(dID)参考医生(dID), 外键(wID)参考Ward(wID) );

答案 3 :(得分:0)

SQL代码对REFERENCES有拼写错误,下面是正确的:

imageFile = this.myFile.nativeElement.files[0]