首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >存储政府表单

存储政府表单
EN

Stack Overflow用户
提问于 2011-02-14 18:54:09
回答 2查看 50关注 0票数 1

我想存储大量已填写的政府表单,如Application for Federal Assistance。形式多种多样,每年都会发生变化。字段类型各不相同,可以是: boolean、string、date、int等。

存储这些表单以完全规范化数据的最佳方式是什么?

±la:

代码语言:javascript
复制
form
+-----------------+-----------+------+-----+---------+----------------+
| Field           | Type      | Null | Key | Default | Extra          |
+-----------------+-----------+------+-----+---------+----------------+
| id              | int(11)   | NO   | PRI | NULL    | auto_increment |
| govt_identifier | char(40)  | YES  |     | NULL    |                |
| description     | char(100) | YES  |     | NULL    |                |
+-----------------+-----------+------+-----+---------+----------------+

filled_form (a form a person has actually filled out)
+-----------+---------+------+-----+---------+----------------+
| Field     | Type    | Null | Key | Default | Extra          |
+-----------+---------+------+-----+---------+----------------+
| id        | int(11) | NO   | PRI | NULL    | auto_increment |
| form_id   | int(11) | NO   |     | NULL    |                |
| person_id | int(11) | NO   |     | NULL    |                |
+-----------+---------+------+-----+---------+----------------+

text_field (a class of input; belongs to a form)
+---------+----------+------+-----+---------+----------------+
| Field   | Type     | Null | Key | Default | Extra          |
+---------+----------+------+-----+---------+----------------+
| id      | int(11)  | NO   | PRI | NULL    | auto_increment |
| name    | char(40) | YES  |     | NULL    |                |
| form_id | int(11)  | NO   |     | NULL    |                |
+---------+----------+------+-----+---------+----------------+

text_value (a particular input record; belongs to a class and filled_form)
+----------------+---------+------+-----+---------+----------------+
| Field          | Type    | Null | Key | Default | Extra          |
+----------------+---------+------+-----+---------+----------------+
| id             | int(11) | NO   | PRI | NULL    | auto_increment |
| value          | text    | YES  |     | NULL    |                |
| text_field_id  | int(11) | NO   |     | NULL    |                |
| filled_form_id | int(11) | NO   |     | NULL    |                |
+----------------+---------+------+-----+---------+----------------+

... continue for all input types
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-14 19:02:17

虽然这是可行的,但您的SQL会有点笨拙,而且非常不直观。您是否考虑过为每个表单单独创建数据模型,然后使用这些数据模型填充表单。它可能看起来更多的前期工作,但您的数据捕获的开发可能会更简单。

票数 1
EN

Stack Overflow用户

发布于 2011-02-14 19:05:14

我会去看看single table inheritance。将每个字段建模为具有子类IntFieldBoolField等的基类Field

Field类将有一个成员Name (string)IntField将有IntValue (int)BoolField将有BoolValue (bit),依此类推。

这要求您在Field-table中为每个可能的类型都有一个列,这是一些空间开销,但另一方面,它为您提供了类型安全。如果您将其建模为单表继承,那么您可能会毫不费力地连接到您最喜欢的ER-mapper。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4991292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档