Common one-to-many table for multiple entities

后端 未结 4 1380
梦谈多话
梦谈多话 2020-12-10 07:13

Suppose I have two tables, Customer and Vendor. I want to have a common address table for customer and vendor addresses. Customers and Vendors can both have one to many ad

4条回答
  •  伪装坚强ぢ
    2020-12-10 08:10

    can you redesign the table to have the following fields:

     Address_Type  (a flag to say that this is a customer, or a vendor)
     ID            (a common ID for both customer and vendor and depending on the flag you know what ID it is)
     Address       (Data of address itself)
    

    or you can have two tables:

    • Address table, where no reference to types of address it is. i.e. to have both
      • entity ID (key)
      • Address
    • address type table, where it would point at entry and have the flag outside the table to have:
      • entity ID (FK to entity ID in the above table)
      • entity type (customer or vendor)

提交回复
热议问题