31st December 2007 - 2 minutes read time
MySQL uses the datatype TINYINT to store boolean values. MySQL stores the value as TINYINT(1) which is the same as a bit so the value is either 0 (false) or 1 (true). Using boolean fields can be very useful, but it can be costly in processing as to change the value you have to query the database, find out the value of the field and then act accordingly.
Here is a simple MySQL query that can be used to toggle the value already present in the TINYINT field without having to do any pre-querying.
UPDATE table SET field = 1 - field