Results 1 to 40 of 50

Thread: Inventory System Table Design

Threaded View

  1. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Inventory System Table Design

    It does not make sense to me, in a SQL world, to have a RAW material table and a Order table.

    You should have a single inventory table - something like this (and this is just for example purposes):

    Product Id
    Transaction Date
    Transaction Type (C for CREDIT, D for DEBIT)
    Transaction Sequence (if needed)
    Reason Code (I for initial quantity, R for restock, O for order, A for adjustment)
    Quantity

    So you would end up with data like this:

    Code:
    ProdId   TransDate    Type  Seq  Reason  Quantity
    000001  2004-02-01    C     001     I       50
    000002  2004-02-01    C     001     I      100
    000001  2004-02-10    D     001     O       20
    000001  2004-02-10    C     002     R      100
    000002  2004-02-20    D     001     O       99
    000001  2004-03-01    C     001     A        2
    000002  2004-03-01    D     001     A        1
    Some initial stock of product 000001 and 000002 on 2004-02-01.

    Then an Order and Restock of product 000001 on 2004-02-10.

    Order of product 000002 on 2004-02-20.

    Then some stock adjustments on 2004-03-01 - found out we had 2 more of product 000001 and that the remaining quantity of product 000002 was lost/damaged.

    This main INVENTORY table drives everything about the quantity of stock - on-hand, ordered, sold - all figures - date driven.

    You have additional tables for order info - linked however you want - maybe with product id, date and sequence - only when you have a REASON code of "O" for order.

    This respects the "set-based" logic that you are supposed to use in SQL - and loses the old "record-by-record" processing techniques that we should avoid in SQL.
    Last edited by szlamany; Sep 3rd, 2007 at 09:02 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width