Home Ask Login Register

Developers Planet

Your answer is one click away!

StackOverflowed February 2016

Table for site options -- how to handle multiple value types?

I'm creating a (MySQL) table for site options, that will have multiple key/value rows (option_name, option_value). Some values will be boolean, some will be strings(varchars) and some might be int. Currently I have option_value set up as a varchar so that it's able to store all the values. Is there a better way for this? I was thinking of having 3 rows (enum for true false, int for int_value and varchar for string_value), however that seems inefficient. Is there a better way and/or am I doing this wrong?


Dave February 2016

I'd prefer to have the three different columns representing the value types, as opposed to having just one over-loaded column. I like the fact that the 3 columns are sort of self-explanatory (assuming pertinent naming), and that I wouldn't have to write some sort of adapter to correctly handle the 3 values types that are stored in a single column.

Post Status

Asked in February 2016
Viewed 1,665 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life