質問

My database holds template forms and real forms having values. Users will be able to create custom template forms with different types of fields. I will keep values in a separate table.

Forms table:

Id | Name | TemplateId

FormFields table:

Id | FormId | Name | ValueType (nvchar)

Values Table

FieldId | Value

When user designs a form it is saved into forms table having TemplateId NULL. Also FormFields table stores the fields that will be used for this form. Later when user creates a real form using that template, the real values of this form (derieved from FormFields) will be stored in Values table. Now, the value column in Values table seems to be sql_variant type. If I don't use sql_variant how can I solve this problem?

Ps: What about creating different tables for each kind of values? TableIntValues, TableBoolValues etc?

http://www.jotform.com/ can be a good sample for my project.

役に立ちましたか?

解決

I would suggest using separate columns for the separate data types, along these lines:

FieldId | StringValue | IntegerValue  |  DateTimeValue

That way you can have queries run over the data sensibly, and also keep it type safe. You would obviously need logic to ensure that the data gets populated correctly, and a constraint to ensure only one column is populated and not all are NULL.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top