How to handle an unknown data type in a single table

I have a situation where I need to store a common piece of data (maybe int, float or string) in my database, but I do not know in advance what it will be. I need a table (or less preferably tables) to store this unknown typed data.

I think what I'm going to do is have a column for each data type, use only one for each record and leave the rest NULL. This requires some logic over the database, but this is not a very big problem, because I will represent these entries in the models anyway.

Basically, is there a better way to do something like this? I have not come up with anything that is smaller than this, but it seems like this is a fairly common problem. Thanks in advance.

EDIT: Also considered to be 3NF?

0
source share
3 answers

You can easily do this if you used SQLite as a database:

Any column in the version 3 database, with the exception of the INTEGER PRIMARY KEY column, can be used to store any type of value.

For other RDBMS systems, I would choose the Philip solution .

, (-) - , ( ). , , ... , , .

+1

, , . ( , , .) , .

+1

, , . , (, , ).

, , .

0

All Articles