Which MySQL Data Type To Use For Storing Boolean Values?

In this tutorial, we will find Which MySQL Data Type To Use For Storing Boolean Values MySQL does not have any such kind of data type as Boolean but we make int as TINYINT to store only two values that are zero or one where zero means false and one means true.

MySQL

DataTypes In MySQL

There are different types of data types in MySQL where we can enter any type of data in these selected we have generally Three types Like Number, String, and Date and each has its own examples.

For example, Numerical has integer, Decimal, Byte, TINYINT, MEDIUMINT, Float, Double, etc and each of these examples has its own range of storing the data size. For example, in the case of Byte, it can hold values from 1 to 63 similarly each of the examples has its range.

On the same note, we have TINYINT which has a range of only two values o and one whereas in the case of a boolean also we have only two digits So we consider TINYINT as Boolean and use it.

As per our convenience, we use the digits as per our requirements where we assigned zero as false and one as true so that we can use it as a boolean.

TINNYINT Type Of Numbers

We use it as Boolean just because of its property of storing only two values where we use it when we are required to get the data in either of the form and we meant to give the options of only two to the users.

For Assigning the datatype as TINNYINT to a variable or column follow the example which clearly shows how we can assign only Zeroes and One to the Variables.

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  is_active TINYINT(1)
);

To learn more about Which MySQL Data Type To Use For Storing Boolean Values visit Making Boolean types of data out of TINNYINT.

To learn more MySQL Problems And Tutorials about Mysql and for programming in Different programming languages, tutorials and problems visit  Python Tutorials and Problems.

Leave a Comment

%d bloggers like this: