From the course: SQL Server Database Triggers

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using the deleted logical table

Using the deleted logical table - SQL Server Tutorial

From the course: SQL Server Database Triggers

Start my 1-month free trial

Using the deleted logical table

- [Instructor] Using the temporary deleted table, we can set up a trigger that'll automatically copy records into an archive table whenever they're removed from the main table. To see how this works, we're going to create two tables, one called vendors and a second one called vendor archive. Both of these tables will be almost identical the vendor's table will have a column for vendor ID that'll be the primary key for the table and a second column to store the vendor name. The vendor archive table will have the same primary key and vendor name columns as well as a third column called date archived. This will allow us to store a timestamp so that we can know exactly when a record was moved from the vendor's table into the archive. So the idea is that we would normally use the vendor's table for our day to day operations. If it ever comes a time where we want to delete a vendor, the trigger will step in and instead of…

Contents