From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

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

Counting shipments received

Counting shipments received

The first trigger that I want to write for the inventory management system is to insert a row into the InventoryAudit table anytime a change is made to the quantity of products on hand. To get started, let's just review the starting state of both of the tables that we'll be working with. So I'll select everything from Products and select everything from InventoryAudit. In the Products table, we currently have four products and they all have a quantity on hand of zero. There aren't any rows inside of the InventoryAudit table yet. So what I want to happen is anytime we update the quantity inside of the Products table, we're going to add in a new row into the audit that gives me the product that was changed the time the change happened, the old quantity and the new quantity that's being inserted into the Products table. In order to do that, we're going to create a trigger, and that starts on line number 12. So we're going to create a trigger called InventoryChangeLog. And it's going to…

Contents