I am new to using SQL developer.
This is hw for my class, and I’ve created employee – manager relationship table.
and for case a. if a manager loses his job, then the manager field should be set to null.
and for case b. if a manager loses his job, then his employee also loses his job.
my table looks like this
lastName | jobTitle | Department | employeeID | fk_employeeID | fk_employeeID1
I am not sure why I get 2 employeeIDs.
here is my DDL code:
CREATE TABLE Employee
(
lastName varchar (255),
jobTitle varchar (255),
Department varchar (255),
id_Employee integer,
fk_Employeeid_Employee integer NOT NULL,
fk_Employeeid_Employee1 integer,
PRIMARY KEY(id_Employee),
UNIQUE(fk_Employeeid_Employee),
FOREIGN KEY(fk_Employeeid_Employee) REFERENCES Employee (id_Employee),
FOREIGN KEY(fk_Employeeid_Employee1) REFERENCES Employee (id_Employee)
)
I think I have to use “on delete cascade” for a and b, if you know how to do it, please help.
Probably a little late for your homework, but in case someone else comes along.
I am not sure why you have multiple fk_employeeIDs… I am assuming this is the id of the employee’s manager. If this is the case, the code above should do what you want. If the manager is deleted, the fk_employeeID fields will be set to null. Also any changes to the manager’s id will be reflected in the foreign key field.
Hope that helps,