sql boolean ddl code example

Example: boolean in sql

#Oracle
#The recommended way of storing booleans in Oracle SQL is to use a NUMBER(1) field.
#This can store 1 as true and 0 as false.

CREATE TABLE testbool (
  sometext VARCHAR2(10),
  is_checked NUMBER(1)
);


#SQL Server
#A BIT data type is used to store bit values from 1 to 64.
#1 for TRUE and 0 for FALSE.

CREATE TABLE testbool (
  sometext VARCHAR(10),
  is_checked BIT
);


#MySQL
#A BIT data type is used to store bit values from 1 to 64.
#1 for TRUE and 0 for FALSE.

CREATE TABLE testbool (
  sometext VARCHAR(10),
  is_checked BIT(1)
);


#PostgreSQL
#PostgreSQL has a Boolean Data Type
#TRUE: represented by TRUE, ‘t’, ‘true’, ‘y’, ‘yes’, ‘on’, ‘1’
#FALSE: represented by FALSE, ‘f’, ‘false’, ‘n’, ‘no’, ‘off’, ‘0’

CREATE TABLE testbool (
  sometext TEXT,
  is_checked BOOLEAN
);

Tags:

Sql Example