简体   繁体   中英

MSSQL: Priority level of Delete Cascade vs FOR Delete Trigger

I would like to know what happens when a row in a parent table is deleted. That is, what would happen next, will TRIGGER FOR DELETE be executed or Delete Cascade ?

Predicament: Trigger needs to get data from child table but if Delete Cascade is executed before the trigger, there would be no data to work with in the Delete trigger .

In short which of these two is correct:

ROW DELETED -> DELETE CASCADE LOGIC -> FOR DELETE TRIGGER LOGIC OR

ROW DELETED -> FOR DELETE TRIGGER LOGIC -> DELETE CASCADE LOGIC

The trigger fires after the rows are deleted. So the child rows will be gone as well. If this is not going to work for you, you might want to consider an Instead Of trigger so you can control things a bit better. You can read more about them here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM