[New to DB triggers/transactions]
In my app, my users are allowed to create, edit and delete rooms. In the event that a room with items assigned to it gets removed, I want to default their room location to a generic room called “unassigned.” Right now I’m doing this in the application level. My question is, should I be doing this in the DB level? If this should indeed occur in MySQL using triggers, how do I go about making my app aware of any failures or successes?
That’s usually best.
Code belongs in the application.
Data belongs in the database.
Code does not belong in the database, any more than data belongs in the application code.
Truggers are generally a very bad idea because they fragment the processing logic into two places — the application and the database.
It’s often best to have the application logic in one place. Outside the database.
The data is the most valuable part of the application. Don’t pollute it with triggers or other bits of application logic.
[This answer will be downvoted by folks who like stored procedures and triggers in the database.]