Results 1 to 21 of 21

Thread: How Many Table I Need To Do......

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    25

    Re: How Many Table I Need To Do......

    thx for your help guys

    yah each product has a unique serial!..., for that it depend on quantity

    if quantity of a product is 25 piece = we will need 25 serial number

    tblSerial (SerialId, ProdId, Quantity, SerialNumber)
    here , we have to make the quantity 1 for each product!!!!

    because qty and serial in the same table....

    i think we need another table for serials..

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: How Many Table I Need To Do......

    I'm not sure I follow that:

    If you have PRODID=123 for example and need 25 different QUANITIES, then you fill:

    Code:
    tblSerial (SerialId, ProdId, Quantity, SerialNumber) 
    
                101       123       1       SNABC1
                102       123       2       SNABC2
                103       123       3       SNABC3
                104       123       4       SNABC4
                105       123       5       SNABC5
    .
    .
    .
                121       123      21       SNABC21
                122       123      22       SNABC22
                123       123      23       SNABC23
                124       123      24       SNABC24
                125       123      25       SNABC25
    So there is an arbitrary SERIALID - that relates to a particular PRODID+QUANTITY combination. In that table is stored the SERIALNUMBER.

    In a way, the SERIALID is not needed - the primary key of this table could be the PRODID+QUANTITY combination. That makes a nice key in MS SQL 2000 when it's CLUSTERED, as all the QUANTITY info about a particular PRODID is in a single cluster on the disk (since the rows are so small), so I/O to retrieve info is very fast.

    *** 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

  3. #3
    ex-Administrator brad jones's Avatar
    Join Date
    Nov 2002
    Location
    Indianapolis
    Posts
    6,614

    Re: How Many Table I Need To Do......

    So the answer to the original question seems to be.....


    4


    <and yes, I'm being coy and wasting a 1/10th of a second's worth of bandwidth, but the question did simply ask for a number.>
    Have you given out your reputation points today? Select the Rate This Post link to give points for good posts!
    -------------------------------------------------------------
    Brad! Jones
    Lots of Software, LLC
    (I wrote: C Programming in One Hour a Day) (Dad Jokes Book) (Follow me on Twitter)

    --------------------------------------------------------------

  4. #4
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: How Many Table I Need To Do......

    Customer - (CustID, etc)
    Order - (OrderID, CustID, etc)
    Item - (Item_Serial_No, OrderID, ProductID, etc)
    Product - (ProductID, etc)

    So a product might be "Widget". An Item might be "Widget1". And an order might have entries for "Widget1", "Widget2", "Widget3" etc.

    You won't need a quantity on the order table because it will be a count of Items where ProductID = "Widget"

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    25

    Re: How Many Table I Need To Do......

    Thx alot FunkyDexter , i think its the right way...

    i have changed something to display quantities...., like

    customers (ID, CustomerName)
    Products (ID , ProductName)
    Invoice (ID,CustomerID,PurchaseDate,DateIn)
    Invoice Record (ID , QTY , InvoiceID, ProductID)
    record details (ID , RecordID , SerialNumber)

    thats will work too

    but the problem , how to retrieve all DATA for Invoice #1 ?
    i think it needs many joins

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: How Many Table I Need To Do......

    select * from invoice i
    inner join invoice_record ir
    on i.ID = ir.InvoiceID
    inner join record_detail rd
    on ir.ID = rd.RecordID
    inner join product p
    on p.ID = ir.ProductID
    where i.invoiceID = 'the invoice youre looking for'

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