From the course: Hands-On Advanced SQL Server: Strategies and Techniques

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

DML triggers

DML triggers

- [Instructor] Data manipulation language triggers or DML for short, lets SQL Server respond to table changes like inserts, updates or deletes the moment they happen. You don't need to call the trigger manually, it fires automatically, and can either log the action, validate the data, or even block the operation altogether. Let's see exactly how this works. Now in front of us, I have queued up the syntax that is actually going to create a trigger called TRG Actor's Change. This trigger is set to run after any change to the actor's table, whether it's an insert, an update or a delete. Right now, all it does is print a message. But in a real world system, you might use this to write to an audit log or notify another process. Now let's test this out. Our first step is to run this create trigger statement. So I'm going to go to the top here, and click run on active connection. We can see that the trigger has been created successfully. We do not see an error message appear. Now that we've…

Contents