Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Representing boolean values 1

Status
Not open for further replies.

TonyGroves

Programmer
Aug 13, 2003
2,389
IE
Does anybody out there have any advice as to the best way to store a non-null boolean field? I have tried the following, but none are really satisfactory:

ENUM('0','1') NOT NULL
Problems: there are three possible values ('0', '1', ''), and a '0' value in numeric context evaluates to 1!

ENUM('1') NOT NULL
Problem: the default value is '1' (any other specified default is rejected).

ENUM('1')
Problem: there are three possible values (NULL,'1','').

TINYINT(1) UNSIGNED NOT NULL
Problem: it's not obvious that it's a boolean field, and there are 256 possible values.


Until a month ago, my database was using Paradox tables, which support a BOOLEAN type with values FALSE and TRUE; it's a pity MySQL hasn't got something similar.
 
use TINYINT with 0,1 values

or CHAR(1) with 'T','F' values

you moved databases once, you may move again, so stay away from the proprietary stuff like ENUM

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top