开发者

How can I store data in a vertical table without losing precision?

开发者 https://www.devze.com 2023-01-10 09:10 出处:网络
I would like to have a vertical table (I know, I know... it\'s pretty much unavoidable) that is able to store an identifying field, the value, and the original type. Obviously the value field needs to

I would like to have a vertical table (I know, I know... it's pretty much unavoidable) that is able to store an identifying field, the value, and the original type. Obviously the value field needs to be something generic or I won't be able to store various different types of data in it (varchar, text, int, decimal, bit, etc).

What suggestions do you have for this t开发者_运维问答ype of setup that would allow me to not lose precision on number data types while offering flexibility and ease of use?


Your best bet is definitely a VARCHAR column, given that there are pretty standard mechanisms to convert most types to/from a String.

Please bear in mind that every time someone makes a table like this, a kitten dies. Seriously, find a better way.


You're going to be storing the data vertically, but for the most part, aren't you going to end up taking certain types of values and breaking them out horizontally anyway? I've seen systems where they have generic type columns of : varchar, int, float, date.

It will take some more coding to determine which column to use for what field; otherwise, you'll just have to deal with converting to another format.

0

精彩评论

暂无评论...
验证码 换一张
取 消