BOOLEAN
- SQL course
- Beginner
- Lesson 28/115
- 4 min
Learn the true/false logical type.
BOOLEAN
BOOLEAN holds true or false. Values are TRUE, FALSE or NULL.
CREATE TABLE products (
in_stock BOOLEAN
);In_stock TRUE means the product is in stock, FALSE means not.
The table products is created.
BOOLEAN — details
Some databases use TINYINT(1) instead of BOOLEAN; 0 is false, 1 is true. In conditions you can use a BOOLEAN column directly: WHERE in_stock.
Practice BOOLEAN
Add an in_stock BOOLEAN column to products.
Starter code
-- stock column
CREATE TABLE products (
in_stockSample solution
CREATE TABLE products (
in_stock BOOLEAN
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Boolean type
CREATE TABLE t (active ____);
CREATE TABLE t (active BOOLEAN);
Explanation: BOOLEAN is the right answer.
2 BOOLEAN: match the terms
| Term | Meaning |
|---|---|
BOOLEAN |
logical |
TRUE |
true |
FALSE |
false |
NULL |
null |
3 How many values does BOOLEAN take?
- Unlimited
- Two: TRUE, FALSE
- One: TRUE
- Three: TRUE, FALSE, NULL Correct answer
Explanation: BOOLEAN takes TRUE, FALSE and NULL.