How to design a database for User Defined Fields?

前端 未结 14 603
花落未央
花落未央 2020-11-27 08:37

My requirements are:

  • Need to be able to dynamically add User-Defined fields of any data type
  • Need to be able to query UDFs quickly
  • Need to be
14条回答
  •  执笔经年
    2020-11-27 09:35

    In the comments I saw you saying that the UDF fields are to dump imported data that is not properly mapped by the user.

    Perhaps another option is to track the number of UDF's made by each user and force them to reuse fields by saying they can use 6 (or some other equally random limit) custom fields tops.

    When you are faced with a database structuring problem like this it is often best to go back to the basic design of the application (import system in your case) and put a few more restraints on it.

    Now what I would do is option 4 (EDIT) with the addition of a link to users:

    general_data_table
    id
    ...
    
    
    udfs_linked_table
    id
    general_data_id
    udf_id
    
    
    udfs_table
    id
    name
    type
    owner_id --> Use this to filter for the current user and limit their UDFs
    string_link_id --> link table for string fields
    int_link_id
    type_link_id
    

    Now make sure to make views to optimize performance and get your indexes right. This level of normalization makes the DB footprint smaller, but your application more complex.

提交回复
热议问题