Database normalization design - single or multiple tables

后端 未结 7 1614
臣服心动
臣服心动 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 16:03

    My opinion would be that if

     // Then depending on user selection, either these fields need to be specified 
     // (could be factored out to a separate table):
     {
     - InternalAccountID (integer, with a FK)
     - InternalCompanyID (integer, with a FK)
     }
    
     // Or these (could be factored out to a separate table):
     {
     - ExternalAccountNumber (free text string)
     - ExternalCompanyName (free text string)
     - ExtraInformation (free text string)
     }
    

    are always 1:1 with an order (i.e., you can't have 3 accountIDs), then leave it as one table. To take care of your null issue, you could add one more column called InternalCustomer (boolean) or CustomerType (varChar) that you could use to define an internal or external customer to know which of the two sets of fields you should look at for a specific customer.

    Since we don't know the full use of this data or the schema for the entire DB, any response on this can't really be fully qualified.

提交回复
热议问题