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

2016-09-04 09:20:50 +08:00
 meloduet

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

1983 次点击
所在节点    问与答
6 条回复
uyhyygyug1234
2016-09-04 09:49:44 +08:00
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
2016-09-04 10:54:14 +08:00
比较简单的做法 ,自定义 html ,可以将 html 抽象成 json 存在数据库
tftk
2016-09-04 12:19:29 +08:00
EAV
Jsonb
Comdex
2016-09-04 12:49:46 +08:00
用文档型非关系数据库
huamei
2016-09-04 17:10:54 +08:00
再建一个 schema 表,或者使用 mongodb
zrp1994
2016-09-04 19:27:57 +08:00
用非关系型数据库

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/303770

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX