I need to create two tables such as:
Id_faculty_referenceandId_professorare primary keys (that works)Id_deanis a foreign key with reference toId_professorId_facultyis a foreign key with reference toId_faculty_reference(the problem).
I tried this:
CREATE TABLE Faculty(
Id_faculty_reference int PRIMARY KEY,
faculty_name varchar,
Id_dean int
);
CREATE TABLE Professors(
Id_professor int PRIMARY KEY,
Name varchar,
Last_name varchar,
Salary int,
Id_faculty int REFERENCES Faculty(id_faculty_reference)
);
ALTER TABLE Faculty ADD FOREIGN KEY (Id_dean)
REFERENCES Professors(id_professor);
The problem comes when I try to add information into the tables. If I try to add info into Faculty, there is no reference, because Professors is empty:
Key is not present in table "Professors"
If I try to add info into Professors, there is no reference because Faculty is empty:
Key is not present in table "Faculty"
The mistake makes sense to me, but my professor says that what he asks can be done; how can I do this?