I created this table:
CREATE TABLE OfficialEmployee
(
EID Integer not null foreign key references Employee(EID),
StartWorkingDate date not null ,
Degree char(20) not null,
Department char(50) not null,
DID Integer not null foreign key references Department(DID)
);
which references the table Employee
by the DID
:
CREATE TABLE Employee
(
EID Integer not null PRIMARY KEY,
FirstName char(30) not null,
LastName char(30) not null,
BirthDate date not null,
CellPhoneNumber Integer not null,
City char(30) not null,
StreetName char(30) not null,
Number Integer not null,
Door Integer not null
);
CREATE TABLE Department
(
DID Integer not null PRIMARY KEY,
Name char(30) not null,
Description char(200) not null,
Manage Integer not null FOREIGN KEY REFERENCES OfficialEmployee(EID)
);
and I want to make a constraint that when OfficialEmployee
is deleted, the record of his in Employee
will be deleted too only if he is not a manager (in the Department
table) else it will (using cascade).
How can I do that?
(I'm using SQL Server)