From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

What are SQL Server triggers?

What are SQL Server triggers?

Let's kick things off with a discussion about what triggers are and why they're useful in a SQL Server database. Triggers are a special kind of stored procedure, but instead of starting them manually or calling them with an application like traditional stored procedures, triggers are executed automatically by the server in response to specific events. With triggers, you can essentially have SQL Server watch for a certain activities and then perform actions that you specify whenever those events happen to occur. To create a trigger, you first need to ask yourself two questions. The first question is when do you want the trigger to fire or activate? The second question is what commands do you want the trigger to execute once it started? To answer the "when" question, we have a couple of different options that can be split into three categories. These are the events that SQL Server will be watching for that will start the actions defined in the trigger. The first category is in response…

Contents