From the course: Complete Guide to Advanced SQL Server

Unlock the full course today

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

Subtract items sold

Subtract items sold

The next trigger that I'll add to the inventory management system is to update the timestamps in the Products table any time the quantity on hand goes up or down. Let's start by taking a look at the Products table just to review where we're at. We have five products currently. The quantity on hand for product number one is currently set to 10, but it's zero for everything else. Now if you remember, the Products table has two columns, that store dates and times. That's the LastRestocked column and the LastSold columns. Now, I'm going to make an assumption here, and this might be a little bit of a simplification for the sake of the example, but I'm going to say that when the quantity of units decreases, that means that a product was sold. And when the quantity increases, that means that a product was restocked from the warehouse. I say this is a simplification because in the real world, there are more reasons why inventory levels might rise and fall. That could include products being…

Contents