1

I have created 3 tables.

create table Employees 
( eid integer, ename char(20),age integer,salary real);

create table Departments 
(did integer,dname char(20));

create table Works 
(eid integer,did integer);

The Works.eid is a foreign key referencing Employees.eid, and the Works.did is a foreign key referencing Departments.did

I now need to create two triggers listening to the delete event on the Employees and Departments respectively, and after a deletion on the Employees table or the Departments table, the deleted employee or department should also get deleted from the Works table.

Im a Noob, any help apreeciated.

1 Answer 1

1

Just use ON DELETE CASCADE when defining the foreign keys.

http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.