V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
meloduet
V2EX  ›  问与答

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

  •  
  •   meloduet · 2016-09-04 09:20:50 +08:00 · 1962 次点击
    这是一个创建于 2795 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    6 条回复    2016-09-04 19:27:57 +08:00
    uyhyygyug1234
        1
    uyhyygyug1234  
       2016-09-04 09:49:44 +08:00   ❤️ 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
    C0dEr
        2
    C0dEr  
       2016-09-04 10:54:14 +08:00
    比较简单的做法 ,自定义 html ,可以将 html 抽象成 json 存在数据库
    tftk
        3
    tftk  
       2016-09-04 12:19:29 +08:00 via iPhone
    EAV
    Jsonb
    Comdex
        4
    Comdex  
       2016-09-04 12:49:46 +08:00
    用文档型非关系数据库
    huamei
        5
    huamei  
       2016-09-04 17:10:54 +08:00
    再建一个 schema 表,或者使用 mongodb
    zrp1994
        6
    zrp1994  
       2016-09-04 19:27:57 +08:00 via iPhone
    用非关系型数据库
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2515 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:21 · PVG 21:21 · LAX 06:21 · JFK 09:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.