I have come across a need of storing runtime determined values in a SQL database.
For example, there is a GUI where a user can add new editable fields. So the user adds a field
Name, chooses the value type
String and fills in the value
Then the user adds a new field
Money, chooses the value type
Decimal and fills in the value
As seen above, the user is able to add any fields with any value types.
My idea is to have a SQL table schema as follow:
- FieldName (varchar) - eg.
- FieldType (varchar) - eg
- FieldValue (varchar) - eg.
This would mean that I can store any pre-defined data type in the table whether it's a
The problem is that I am not sure it's the best approach to cast those values to
string and then cast again when reading from the table.
Another option would be to have a column of each type but that sounds even worse.
Does my approach to cast everything to string sounds sensible or should I try something else?