meloduet
V2EX  ›  问与答

这种情况如何设计数据库?

  •  
  •   meloduet · Sep 4, 2016 · 2683 views
    This topic created in 3563 days ago, the information mentioned may be changed or developed.

    是这样的,我正在做一个调查问卷系统, 每个新建的调查问卷的表单字段都是可以自定义的, 那么问题来了, 我需要为每个填表的用户添加一个数据库字段, 但是既然是自定义字段, 那么用列名表示字段名就不行了,而且可以创建不止一个问卷,我该怎么办?

    6 replies    2016-09-04 19:27:57 +08:00
    uyhyygyug1234
        1
    uyhyygyug1234  
       Sep 4, 2016   ❤️ 1
    1.新建一个表 存 StringValue1, StringValue2... IntValue1, IntValue2,...

    2.创建一个动态表, 用户加了你就加。会有性能问题

    3.生成一个表, UDFName, UDFDataType, and Value. When a new UDF gets added, generate a View which pulls just that data and parses it into whatever type is specified. Items which don't meet the parsing criteria return NULL.

    4.Create multiple UDF tables, one per data type. So we'd have tables for UDFStrings, UDFDates, etc. Probably would do the same as #2 and auto-generate a View anytime a new field gets added

    5. XML DataTypes? I haven't worked with these before but have seen them mentioned. Not sure if they'd give me the results I want, especially with performance.


    http://stackoverflow.com/questions/5106335/how-to-design-a-database-for-user-defined-fields
    z67nnciQnb7r8bLf
        2
    z67nnciQnb7r8bLf  
       Sep 4, 2016
    比较简单的做法 ,自定义 html ,可以将 html 抽象成 json 存在数据库
    tftk
        3
    tftk  
       Sep 4, 2016 via iPhone
    EAV
    Jsonb
    Comdex
        4
    Comdex  
       Sep 4, 2016
    用文档型非关系数据库
    huamei
        5
    huamei  
       Sep 4, 2016
    再建一个 schema 表,或者使用 mongodb
    zrp1994
        6
    zrp1994  
       Sep 4, 2016 via iPhone
    用非关系型数据库
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1606 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 16:15 · PVG 00:15 · LAX 09:15 · JFK 12:15
    ♥ Do have faith in what you're doing.