I have some form data I'm storing in a database. Up till now I've been storing values for checkboxes as VARCHAR with the value 'checked' - which seems silly. Since there are only two values, why not just do this in some kind of binary fashion - store a "1" for 'checked', and a "0" (or null) for unchecked.

What (MySql) column type and value choices do people typically use for this sort of thing? Looking for a 'best practice' or otherwise preferred method here.

  • Bob

    I use tinyint, as the bool type actually uses a tinyint anyway. Well so the manual says.

      You can use the ENUM column type.

      ENUM('1','0')

      You could choose whatever you like for true or false

      ENUM('True','False')

      etc . . .

        i typically use a CHAR(1) field, that is either "Y" or NULL

          Write a Reply...