Right, let’s talk about timing. This isn’t about your morning coffee; it’s about whether your trigger fires before the main event or after it. The choice between BEFORE and AFTER isn’t just a preference—it fundamentally changes what you can and cannot do, and it all boils down to one thing: access to the NEW and OLD records.
Think of it like this: a BEFORE trigger is your bouncer at the club door. They can check your ID (NEW.column), decide you’re not wearing the right shoes, and turn you away (by raising an exception) before you even get in. They can even slip a fake ID into your pocket (change the values in NEW) before the database commits the actual row insert or update. An AFTER trigger, on the other hand, is the security camera in the parking lot. The event (the insert, update, or delete) has already happened. The camera can see what went down, it can log it, it can even call for backup based on what it sees, but it can’t stop the row from entering the database or change its values. The deed is done.