boolean operators in sql code example

Example 1: 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
);

Example 2: sql boolean data type

Oracle: NUMBER(1)
SQL server: BIT

Example 3: logical operators in sql

LOGICAL OPERATORS?
ALL	    (TRUE if all of the subquery values meet the condition)	
AND	    (TRUE if all the conditions separated by AND is TRUE)	
ANY	    (TRUE if any of the subquery values meet the condition)	
BETWEEN	(TRUE if the operand is within the range of comparisons)	
EXISTS	(TRUE if the subquery returns one or more records)
IN	    TRUE if the operand is equal to one of a list of expressions)	
LIKE	(TRUE if the operand matches a pattern)	
NOT	    (Displays a record if the condition(s) is NOT TRUE)	
OR	    (TRUE if any of the conditions separated by OR is TRUE)	
SOME	(TRUE if any of the subquery values meet the condition)

Tags:

Misc Example