How to get parent id in child after delete trigger?

Suppose I have tables:

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

a foreign key is created and cascading deletion is determined by the foreign key relationship.

Now I delete the phone from the telephone table. I want to write the deletion to the Phone table delete trigger.

But I can not get empid in the phone. After removing a trigger, for example

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

because the entry in EmployeePhone was deleted using cascade delete with foreign key relationship.

How to get empid on phone after delete trigger?

+5
source share
1 answer

Try adding another deletion trigger to the EmployeePhone table - the data you need will be available to you.

+4
source

All Articles