On Tue, 13 Jul 2004 15:54:00 GMT, "Xenophobe" <xe*******@planetx.com> wrote:
I have a series of checkboxes and need to store their values in a MySQL
table.
I'm wondering what data type people recommend:
varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"
Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.
Largely comes down to personal preference, I think.
I use 'T'/'F' mainly just because that's the convention at the company where I
work.
0/1 has the advantage that you can use the value as a Boolean value in PHP or
Perl etc.
I wouldn't use anything longer than a byte, though, so that rules out the
wordier 'Yes'/'No' 'True'/'False' options.
In fact in Oracle, which I mostly work with, 1 is two bytes in its internal
storage scheme, whereas 'T' is one byte (unless you're using UTF16 as the
database character set).
MySQL's TINYINT type guarantees a single byte for the number though.
Should be wary of trying to be clever and forming bitmasks in a single column
just to start saving bytes, since you're breaking normalisation rules if you go
down that route.
--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk /
http://www.andyhsoftware.co.uk/space