db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <de...@segel.com>
Subject RE: Best choice for column's data type to represent boolean data
Date Thu, 07 Dec 2006 13:06:50 GMT
> 
> I have a need for columns of boolean data to indicate if items in my
> database have (or do not have) certain attributes.  These are all truly
> yes/no values.  For Derby what is the best approach for me to take (I have
> next to zero database experience so I am not aware of any best practices)?
> In my case if I had t pick performance over storage space in this
> application I would choose performance.  I plan to query using these
> values (along with others); for example select all items that have
> attribute A but not attribute B.
> 
> Currently my application is using 10.1.3.1 but before my next release I
> will be upgrading to 10.2.1.6.
> 
> Thanks,
> 
> Ian
> 
Well the best practice would be to extend the known data types to include a
Boolean. ;-)

There are two options.
You can create a CHAR(1) column, or if the database you could do a
byte/short column as well. 

If you use a CHAR(1) you could represent the Boolean as either ('T' or 'F')
or ('Y','N'). You would also want to put a check constraint on the column
only allowing a true and a false value.

You could also use a 1 or a 0 in the column as well and provide the same
check constraint, however using a T/F or Y/N provides a visual cue that
would be missing from a numeric solution.

HTH

-G




Mime
View raw message