我目前正在我的大学里上SQL课,并且目前正忙于我教授分配的复习问题。我的日程表表不断出现错误。我觉得这与我的外键呼叫有关,但是我不确定100%吗?对于Schedule表,她希望DoctorID是外键,而date / clinic是主键
CREATE TABLE Doctor (
DoctorID numeric(3) not null,
Drname varchar (25) not null,
phonenum varchar (12) not null,
CONSTRAINT DoctorID_pk PRIMARY KEY (DoctorID)
);
CREATE TABLE Patient (
PatientNum numeric (5) not null,
SSNum numeric (9) not null,
PTName varchar (25) not null,
DOB numeric (8) not null,
PAddress varchar (40) not null,
DateAdmit numeric (8) not null,
Clinic varchar (30) not null,
CONSTRAINT PatientNum_pk PRIMARY KEY(PatientNum)
);
CREATE TABLE Treatment (
Treatmentcode numeric (6) not null,
Description varchar (50) not null,
CONSTRAINT Treatmentcode_pk PRIMARY KEY(Treatmentcode)
);
CREATE TABLE PatDocTreatment (
PatientNum numeric (5) not null,
DoctorID numeric (3) not null,
Treatmentcode numeric (6) not null,
DateofTreat numeric (8) not null,
Comments varchar (80) not null,
CONSTRAINT PK_PatDocTreatment PRIMARY
KEY(Patientnum,DoctorID,Treatmentcode,DateofTreat),
FOREIGN KEY(PatientNum) REFERENCES Patient(PatientNum),
FOREIGN KEY(DoctorID) REFERENCES Doctor(DoctorID),
FOREIGN KEY(Treatmentcode) REFERENCES Treatment(Treatmentcode)
);
CREATE TABLE Schedule (
DoctorID numeric (3) not null,
SchDate numeric (8) not null,
Clinic varchar (30) not null,
Hoursworked numeric (3) not null,
CONSTRAINT PK_Schedule PRIMARY KEY(DoctorID,SchDate,Clinic),
FOREIGN KEY (DoctorID) REFERENCES Doctor (DoctorID)
FOREIGN KEY (CLINIC) REFERENCES Patient (Clinic)
);
答案 0 :(得分:2)
您可能错过了计划表中最后两个外键声明之间的逗号。