You could use a separate flags table that contains the
parent record key, flag name, and flag value.

You can then add and delete flags at will.

Philip Mak wrote:

> I have an application that requires the storage of various flags (by
> "flag", I mean a variable that is either 1 or 0).
> 
> What's a good way of doing this? I've thought about two ways:
> 
> Method 1: Make a TINYINT column for each flag
> 
> I can use TINYINT NOT NULL datatype for storing each flag. The
> disadvantage is that I use 8 bits when 1 bit would have sufficed.
> 
> Method 2: Make a single SET column for all the flags
> 
> I can use a SET for storing all the flags. But the disadvantage is that
> the programming syntax gets a bit more complicated. e.g. instead of being
> able to do:
> 
> SELECT * FROM fanfics WHERE unfinished = 0
> 
> I would have to do:
> 
> SELECT * FROM fanfics WHERE FIND_IN_SET('unfinished', flags) = 0
> 
> Does anyone have other suggestions?
> 
> Another concern that I have is the time required to add a new flag. If I
> have a large table, adding a new column to the table can be quite time
> consuming. (I'm guessing if I use the SET method, adding a new flag would
> be instantaneous unless the number of flags was divisible by 8, requiring
> the SET to expand by one byte.)
> 
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-- 
Gerald L. Clark
[EMAIL PROTECTED]


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to