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.

Using the inserted logical table

Using the inserted logical table - SQL Server Tutorial

From the course: Complete Guide to Advanced SQL Server

Using the inserted logical table

The Inserted temporary table holds the values that are being added to a table through an INSERT command, or the ending values after an UPDATE statement. We can join the values in the Inserted table with the values from the original data table to identify rows that are being modified, and to append additional instructions to the triggering event. I'm going to use the Inserted table to help build a trigger that will identify whether a number is even or odd. To set this up, we'll create a new table called NumberParity. It'll have three different columns. The first column, called RowID will be the primary key for the table. And we'll use the identity specification to automatically generate ID numbers for the row. The second column called MyNumber will store a basic integer value. And then we have a column called Parity that will store an nvarchar text data type. Parity is a word that just describes whether a number is even or odd. So what I want to do is fill in a number to the table, and…

Contents