From the course: SQL Server Database Triggers

Unlock the full course today

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

Subtract items sold

Subtract items sold - SQL Server Tutorial

From the course: SQL Server Database Triggers

Start my 1-month free trial

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 at 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 the product was restocked from the warehouse. I say this as a simplification, because in the real world, there are more reasons why…

Contents