1. Welcome! Please take a few seconds to create your free account to post threads, make some friends, remove a few ads while surfing and much more. ClutchFans has been bringing fans together to talk Houston Sports since 1996. Join us!

Database Gurus

Discussion in 'BBS Hangout' started by what, Jul 5, 2015.

Tags:
  1. what

    what Member

    Joined:
    Dec 4, 2003
    Messages:
    14,588
    Likes Received:
    2,553
    So I am new to database design and I am trying to make a model of my invoicing system.

    I am wondering if this is correct:

    table {customers}
    PK CustomerId

    table {Invoice}
    PK InvoiceId
    FK CustomerId

    table {IvoiceDetails}
    PK InvoiceDetails
    FK InvoiceId
    FK VehicleInfoId
    FK SignatureID

    table {Vehicle}
    PK VehicleInfoID
    yr
    mk
    model

    table {signature}
    PK SignatureID
    attachment

    basically, I am collecting table information in the invoicedetails table. Is this the correct way to do this?
     
  2. heypartner

    heypartner Contributing Member

    Joined:
    Oct 27, 1999
    Messages:
    62,577
    Likes Received:
    56,318
    Looks good.

    The only adjustment I'd make is to notice that InviiceDetail PK is never stored anywhere else, so it it unneeded. It is a Mapping table. Mapping tables usually don't have auto-increment PK. get rid of that column since you will never be able to JOIN on it

    Just make the index for it the combination of FKs that create a unique identifier. This is known as a composite index.

    [edit]
    The InvoiceDetail table should also have customerID as an FK. So the composite index would be InvoiceID_FK and CustomerID_FK, assuming that combo is unique, or maybe just InvoiceID_FK is enough. The other FKs are just for lookup
     
    #2 heypartner, Jul 5, 2015
    Last edited: Jul 5, 2015
  3. what

    what Member

    Joined:
    Dec 4, 2003
    Messages:
    14,588
    Likes Received:
    2,553

    that's great, thank you so much
     
  4. heypartner

    heypartner Contributing Member

    Joined:
    Oct 27, 1999
    Messages:
    62,577
    Likes Received:
    56,318
    Another question: Does the Invoice table hold data. If not just get rid of it
     
  5. what

    what Member

    Joined:
    Dec 4, 2003
    Messages:
    14,588
    Likes Received:
    2,553
    I don't guess it does. I was following the access 2013 bible example.

    The only thing is that i'd need a way to set my invoiceNumber and from what you told me, I probably shouldn't a pk in my lookup table.

    so my OrderDetails Table would look like this:

    table {orderdetails}
    PK InvoiceNumber
    FK CustomerId
    FK SignatureID
    FK VehicleInfo

    I really don't know how that would work
     
  6. what

    what Member

    Joined:
    Dec 4, 2003
    Messages:
    14,588
    Likes Received:
    2,553
    Actually it does hold the date the job was done. Plus I might need it to associate it with my invoice number.

    table {invoice}
    InvoiceId
    CustomerID
    DateofJob

    table {invoiceNumber}
    PK InvoiceNumberID
    FK InvoiceId

    table {orderdetails}
    FK InvoiceNumber
    FK CustomerId
    FK SignatureID
    FK VehicleInfo
     
  7. heypartner

    heypartner Contributing Member

    Joined:
    Oct 27, 1999
    Messages:
    62,577
    Likes Received:
    56,318
    Nah. You don't need a table just to store the Date. That is part of orderdetails.

    OK, so now that I have more info, ignore my other comments beyond just the theory of it.

    In practical terms, just put Date in the OrderDetails. So, OrderDetails is a mapping table to Signature and Vehicle Info, has a date, plus it can be joined on CustomerID.

    Those three tables above can be just one.

    tabel {OrderDetails}
    PK InvoiceNumber
    FK CustomerId
    FK SignatureID
    FK VehicleInfo
    DateOfJob

    What I'm trying to simplify is PKs are needed for Indexing the DB, so it sorts fast. But they are often overused, since composite Index provide the same speed. The way I think about it is if a PK is never stored in another table, then you can never reference it in code, except when humans enter it in a form like CustomerID and InvoiceNumber.

    So,

    In your case, I no longer believe you need composite indexes, but rather you should just get rid of all tables in between Customer and InvoiceDetail.

    just do

    Customer Table
    PK Customer ID
    customer data

    Invoice Table
    PK Invoice Number
    FK Customer ID
    FK Vehicle Data
    FK Signature File
    DateOfJob
    InvoiceDate
    ReceiptOfPayment
    etc about payment info

    So, just four tables. One for customer data, one for Job Data/Invoicing, and two for detail tables that might grow in width or are rarely used, Vehicle Data and Signature.
     
  8. cebu

    cebu Member

    Joined:
    Dec 16, 2013
    Messages:
    1,663
    Likes Received:
    587
    the only issue is your invoice details don't have a line number column which should be a part of your PK

    table {IvoiceDetails}
    PK InvoiceDetails ( InvoiceID, LineNumber)
    FK InvoiceId
    FK VehicleInfoId

    Signature should be in the Header, unless you do partial delivery.
     
  9. what

    what Member

    Joined:
    Dec 4, 2003
    Messages:
    14,588
    Likes Received:
    2,553
    Yes, I know. I am working on that part. It is a little more complicated by the fact that the services I sell varies in price depending on if the method of payment.

    I am thinking that I would have a payment method table:

    table {payment_methodID}
    Payment_method PK
    cash FK
    check FK
    credit card FK
    insurance FK

    table {insurance}
    insuranceID PK
    PricingID PK
    statefarm
    farmers
    etc
    Quanity

    table {cash}
    PricingID PK
    Quantity

    table {pricing}
    PricingID
    $50.00
    $60.00
    Etc
     

Share This Page

  • About ClutchFans

    Since 1996, ClutchFans has been loud and proud covering the Houston Rockets, helping set an industry standard for team fan sites. The forums have been a home for Houston sports fans as well as basketball fanatics around the globe.

  • Support ClutchFans!

    If you find that ClutchFans is a valuable resource for you, please consider becoming a Supporting Member. Supporting Members can upload photos and attachments directly to their posts, customize their user title and more. Gold Supporters see zero ads!


    Upgrade Now