I would like to know if it is possible to update a column (or in general ‘do something’) in an SQL table when an event occurs in another.
More specifically I’d like to know if it is possible to change a value in a particular column in a child table when a row is deleted in parent table. Sort of ON DELETE CASCADEbut without deleting rows just updating them.
The DBMS I am using is MS SQL Server (Express edition).
Thank you very much
Use a trigger on the table that you’re trying to base the event off of, or you can limit access (read the deletion) from that table to happen only through a stored procedure. The code for changing whatever it is you want to change on the other would be maintained in the trigger or stored procedure.
I typically prefer the stored procedure route, but this is just my personal preference.
Stored Procedures
Database Triggers