I have two tables which are linked with the foreign key in the Staff member table. I'm trying to setup the foreign key so that a row in the position table is removed if it has no associated staff members from the Staff Member table. I am using ON DELETE CASCADE however this removes the row even if there are still staff members associated with the position.
Position Table
----------------------------------------------
----Attribute-------Type-------------Keys-----
----------------------------------------------
- Title -- VARCHAR(20) --Primary Key--
- MaxSalary -- DECIMAL(8,2) -- No -
- MinSalary -- DECIMAL(8,2) -- No -
----------------------------------------------
StaffMember Table
-----------------------------------------------------
----Attribute-------Type-----------------Keys--------
-----------------------------------------------------
- StaffNo -- INTEGER -- Primary Key --
- Name -- VARCHAR(20) -- No -
- Salary -- DECIMAL(8,2)-- No -
- StaffTitle -- VARCHAR(20) --FK Position(Title) -
-----------------------------------------------------
CREATE TABLE StaffMember(
StaffNo INTEGER PRIMARY KEY,
Name VARCHAR(20),
Salary DECIMAL(8,2),
StaffTitle VARCHAR(20) FOREIGN KEY REFERENCES Position(Title) ON DELETE CASCADE);