Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parent ID in child after delete trigger?

Suppose I have tables:

Employee(empid, ....)
Phone(phoneid, ...) 
EmployeePhone(empid, phoneid, ...)

there is foreign key created and cascade deleting defined on foreign key relationship.

Now I delete a phone from phone table. I want to record the deletion in Delete trigger of table Phone.

But I can't get the empid in Phone After delete trigger like

select empid from deleted d join EmployeePhone e on d.phoneid = e.Phoneid

because record in EmployeePhone was deleted by cascade delete with the foreign key relationship.

How to got the empid in Phone after delete trigger?

like image 682
KentZhou Avatar asked Oct 09 '22 00:10

KentZhou


1 Answers

Try adding another delete trigger on the EmployeePhone table - the data you require will be available to you there.

like image 143
Mack Avatar answered Oct 13 '22 11:10

Mack