Database normalization design - single or multiple tables

后端 未结 7 1769
臣服心动
臣服心动 2021-01-14 15:28

Should this be represented in the database as 1 table or 3 tables? I and my friend have different opinions about this so I\'d like to see the general views on this. (Maybe

7条回答
  •  醉酒成梦
    2021-01-14 15:59

    Is account information associated with the customer before he can order (i.e. you have enother table where you track which account ID-s given CustomerID can use)? Can you abstract all accounts to a reasonably uniform schema (that one can have a few nulls) fo that you have one universal AccountId (surrogate key) and then Account's table has say 3 varchar fields and one that tracks the kind of the account (used for billing etc.) ?

    If you can do that then your order tracks just one AccountID since the order (as an entity) really doesn't care which payment method was used - it only cares that it's a legit/existing/approved AccountId for that user. Everything else is someone else's business so to speak (billing or checking funds etc.) and that enity and it's processing will need more data anyway.

    This keeps your Order clean and null-free and facilitates separation of concerns as well.

    Conceptually, your Order is really so called fact table - carrying only numbers and FK-s, small in item size but with a huge number of them.

    So:

     Table Order (
         - OrderId
         - Quantity
         - ProductId
         - DiscountId -- sonner or latter :-)
         - AccountId
         - PaymentStatus -- probaly FK as well or predefined constant
     )
    
     Table Account (
         - AccountId
         - BillingInfo  -- akka ext acct number as text
         - PrincialName -- akka ext company name, some equivalent for internal acct-s
         - AdditionalData
     )
    

提交回复
热议问题