how to design a schema where the columns of a table are not fixed

后端 未结 6 2037
春和景丽
春和景丽 2020-12-04 01:24

I am trying to design a schema where the columns of a table are not fixed. Ex: I have an Employee table where the columns of the table are not fixed and vary (attributes of

6条回答
  •  囚心锁ツ
    2020-12-04 01:26

    I recommend using a combination of numbers two and three. Where possible, model tables for standard associations like addresses. This is the most ideal approach...

    But for constantly changing values that can't be summarized into logical groupings like that, use two tables in addition to the EMPLOYEES table:

    • EMPLOYEE_ATTRIBUTE_TYPE_CODES (two columns, employee_attribute_type_code and DESCRIPTION)
    • EMPLOYEE_ATTRIBUTES (three columns: employee_id foreign key to EMPLOYEES, employee_attribute_type_code foreign key to EMPLOYEE_ATTRIBUTE_TYPE_CODES, and VALUE)

    In EMPLOYEE_ATTRIBUTES, set the primary key to be made of:

    • employee_id
    • employee_attribute_type_code

    This will stop duplicate attributes to the same employee.

提交回复
热议问题