Bool Type
A BOOL is a data type mainly used for expressions that will return only two possible values, true and false.
Bool is stored as a bitmap in u64 values.
BOOLEAN is an alias for the BOOL data type. You can create a table using BOOLEAN. However, it will be stored and processed equivalently to BOOL.
- FALSE
- TRUE
Below are a few examples of using a bool data type:
A librarian will create a borrowBook table that he will use to store book borrowing data. The table comprises the borrowed ID, the book name, the borrower, and the book’s returned status, which uses the bool data type.
The borrowBook table has been successfully created after executing the above query:
Run the SELECT statement to get all records from the borrowBook table:
It will return the result as displayed below:
In the below example, the following statement is used to retrieve all the books that have already been returned:
We will get the following results:
Now, we will acquire all of the book records that haven’t been returned yet by running the SELECT statement with a specified WHERE condition as false:
We will get the following results:
In this example, we are going to figure out the returned status of the book “The Lord of the Rings” by executing the SELECT statement with a specified column in the WHERE clause:
The above query will filter all records based on the specified conditions, and we know that Sandra hasn’t returned the book yet:
