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.

Disable nested triggers

Disable nested triggers

By default, SQL Server will allow you to have triggers that execute commands that in turn fire additional triggers, and that'll allow you to create a chain of up to 32 separate events. This is a server-level property called nested triggers. To see this in action, let's create two tables. I've creatively decided to name these FirstTable and SecondTable. The FirstTable is just going to have a RowID and a value that we can place in there. And the SecondTable will have a RowID and a date that we can put in. So let's go ahead and create both of those tables, and then I'm going to create a couple of triggers. Now, the first trigger is going to be on the FirstTable. It'll be an AFTER INSERT table. So any time we insert a new row into the table, we're going to insert a row into the SecondTable. And the value that we're going to put in is just the current date and time. So essentially, we're writing a timestamp into the SecondTable any time we add a row into the FirstTable. So I'm going to go…

Contents