DB2 Creating (faking) a Boolean datatype

When creating a table in DB2, to create a Boolean datatype column (since DB2 doesn’t have this natively) you have to use a check constraint on a smallint column. So if you have a column named “ACTIVE” that you want to be Boolean, you would create the that col like so:

ACTIVE SMALLINT NOT NULL,
CONSTRAINT CCACTIVE1 CHECK (ACTIVE in(0,1))

Then obviously, when you use that field, you can only insert/update using 1 and 0 respectively for your true and false values.

  1. 2 Responses to “DB2 Creating (faking) a Boolean datatype”

  2. By Jeremy Stein on Oct 23, 2006 | Reply

    Ah, good idea. Thanks.

  3. By Alfonso on Dec 11, 2006 | Reply

    Very useful…thaks a lot!

Post a Comment

Close
E-mail It