Proper way to store user defined data in SQL

為{幸葍}努か 提交于 2019-12-02 05:07:56
Mahmoud Gamal

store user defined data in SQL

I think you are looking for the Entity–attribute–value database model in which:

The basic idea is to store attributes, and their corresponding values, as rows in a single table.

Typically the table has at least three columns: entity, attribute, and value. Though if there is only a single relevant entity, e.g. a table for application configuration or option settings, the entity column can be excluded.

See this pages as a start:

I retagged your question with tag, in which you can browse a lot of threads that relate to your case.

As Mahmoud Gamal writes, The model you describe is "Entity/Attribute/Value"; as Borys writes, there are many known problems with this model.

As an alternative, you might consider storing the form entries in a "document" - e.g. XML or JSON - within a relational model.

For instance, you might have a table along the lines of:

FORM_SUBMISSION
--------------------
Submission_ID (pk)
Client_ID (fk to clients table)
Submission_date
SubmissionDocument

I'm using "client" to represent the users who create the form; to retrieve all submissions for a given client, you use a where clause on client_id.

This model makes it harder to run SQL queries against the form submission (though that becomes hard with EAV too when going beyond very simple queries), but it dramatically simplifies the persistence solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!