I have work to do in SQL, and I have a problem about the referencing of a key. So I have two tables:
CREATE TABLE Surveillances
(
NumEns NUMERIC(10) REFERENCES Enseignants,
DateHeureDebut TIMESTAMP(0),
NumSal NUMERIC(4) REFERENCES Salles,
PRIMARY KEY(NumEns, DateHeureDebut)
);
CREATE TABLE Horaires
(
NumEpr NUMERIC(10) REFERENCES Epreuves,
DateHeureDebut TIMESTAMP(0) REFERENCES Surveillances,
PRIMARY KEY(NumEpr)
);
I already created the table Surveillances
, but when I try to create the table Horaires
, this error appears
Error report -
ORA-02270: no matching unique or primary key for this column-list.
I find out that the problem comes from the key DateHeureDebut
which is a primary key in the table Surveillances
, but not in Horaires
.
I tried to modify my Horaires
table, but that didn't work:
CREATE TABLE Horaires
(
NumEpr NUMERIC(10) REFERENCES Epreuves,
DateHeureDebut TIMESTAMP(0),
PRIMARY KEY(NumEpr),
FOREIGN KEY(DateHeureDebut) FROM Surveillances(DateHeureDebut)
);
I just tried this :
CREATE TABLE Horaires
(
NumEpr NUMERIC(10) REFERENCES Epreuves,
DateHeureDebut TIMESTAMP(0),
NumEns NUMERIC(10),
PRIMARY KEY(NumEpr),
FOREIGN KEY(NumEns, DateHeureDebut) REFERENCES Surveillances(NumEns, DateHeureDebut)
);
And it works, I mean no error, but in the Horaires
table there is no NumEns
key.
I have to follow this schema :
The underline words are primary key