IT tutorials
 
Database
 

SQL Server : Constraints and Rock Solid Inventory Systems (part 3) - Updating existing rows

1/19/2013 5:09:00 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Updating existing rows

In all previous examples, we have used INSERT commands to add new inventory rows. Now we need to consider how our system will behave if we allow UPDATEs of existing rows in the inventory trail for a given item. First of all, let's add another history of changes for item #2.

Listing 19. More history for item #2.

Suppose it is discovered that the initial inventory for item #2, entered on January 1st, 2010, should have reflected a quantity of 3, rather than 5, so we need to decrease the amount added for that item.

Listing 20. We cannot update a single row if it is not the last in the history trail for the item.

This UPDATE fails, which is good news, otherwise the CurrentQuantity for any subsequent row in the history trail would be incorrect.

The correct way to UPDATE a row is to include all the downstream ramifications of the change in one command. In other words, if we need to modify the initial inventory entry, then we need to make sure that, at the same time, we correctly adjust all subsequent entries in the history trail for that item. In this case, this will mean updating three rows all at once.

The UPDATE in Listing 21 still fails, because decreasing the original inventory from 5 to 3 means that the final modification on January 5th, 2010 would lead to a negative value of CurrentQuantity.

Listing 21. Updating all inventory rows for a given item at the same time.

If we set @fixAmount to a valid amount, –1 instead of –2, and then rerun Listing 19 it will complete successfully. We can also set @fixAmount to a positive number, run the listing again, and see that again it succeeds, as it should.

Although we have now managed, with some difficulty, to modify a row in the middle of a history trail, we need to emphasize that only inserting rows at the end of history trail is fast and convenient. Correcting history is harder and may be significantly less performant. However, our solution has dramatically simplified and speeded up the most common operation, namely inserting rows at the end of history trails.

 
Others
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us