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.

Read values modified by a trigger

Read values modified by a trigger - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Read values modified by a trigger

When writing a trigger for data manipulation language events such as insert, update, and delete, SQL Server uses two temporary tables behind the scenes. These two tables have the exact same column structure as the table that the trigger is manipulating, and they contain the rows of data that are being affected by the triggering event. We briefly saw one of these temporary tables in the previous chapter. It's called the Inserted table. The other table is called Deleted. Let's take a look at how these work by creating a new table inside of the KinetEcoTRG database. I'm going to create a simple table called Colors. I'll just have two columns. The first column, ColorID, will use the identity feature in order to automatically assign an identity value. And then we have the ColorName column. Let's go ahead highlight these lines and execute them to create the table. Now, I'm going to create a trigger on this table so that we can see the Inserted and Deleted tables. I'm going to create the…

Contents