SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Friday, May 26, 2006

Boolean bit field Which is True False

SQL Apprentice Question
I have a field that I need to query for true and false.
The field is a bit.

Is True 0 or 1.


I can't open Books Online and the download instructions based on my version
SQL 2000, are not clear and I don't know what detailed version I have nor
where to find it.


Celko Answers
>> I have a field [sic] that I need to query for true and false.<<


Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files. Totally different concepts!


>> The field [sic] is a bit. <<


You are missing another basic point here. There is no BOOLEAN data
type in SQL and it is a sign of bad programming to write with lower
level bit flags in a high-level language.

Get a book on RDBMS and read about three-valued logic and NULLs to
learn why this cannot be implemented in the SQL model.


Also, look at C# and VB -- do you use -1, +1, or 0 for BOOLEAN?

1 comment:

test said...

What a dick answer