How to store data with dynamic number of attributes in a database

前端 未结 8 2291
挽巷
挽巷 2020-12-04 13:14

I have a number of different objects with a varying number of attributes. Until now I have saved the data in XML files which easily allow for an ever changing number of attr

8条回答
  •  有刺的猬
    2020-12-04 13:27

    A variation on your 2d solution is just two tables (assuming all attributes are of a single type):

    T1: |Object data columns|Object_id|

    T2: |Object id|attribute_name|attribute value| (unique index on first 2 columns)

    This is even more efficient when combined with 3rd solution, e.g. all of the common fields go into T1.

    Sstuffing >1 attribute into the same blob is no recommended - you can not filter by attributes, you can not efficiently update them

提交回复
热议问题