Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Often other tables have foreign keys to the record to be deleted. What’s a good pattern for treating those related tables for every time a relationship row gets deleted/removed as per the OP blog post?


Really depends on the related data, but there‘s the option to use ON DELETE CASCADE|RESTRICT and set null or set default.

Cascade can be a bit of a footgun, as this can trigger a waterfall of deletes.


Cascades can also lead to deadlocks as I found to my cost the one and so far only time I tried using hard deletes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: