Re: tracking shipments, inventory

From: <>
Date: 27 Dec 2004 07:23:33 -0800
Message-ID: <>

>> negative stock quantities are entirely
possible in this database design but impossible in the real world (putting aside the issue of backorders). Sure I can add logic in procs and triggers to prevent a negative stock situation.... but that's the burdensome and worrisome part. WHAT IF there's a hole in that logic? How do I make bombproof rules to enforce these sorts of temporal constraints?

I'd create a table shipment_piece(shipment_pk not null, delivered_to_pk), one row per a piece. You'd use up some more space, but never ever get negative quantities in stock:

select count(*) from shipment_piece where delivered_to_pk is null

This query never returns negative numbers. And yes, if the pieces are not distinguishable, that refers to a well know 'cat food' problem. Received on Mon Dec 27 2004 - 16:23:33 CET

Original text of this message