Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here

co-founder

MySQL - boolean data type

0 contributions
2 points

Simplest solution:

`is_user_removed` TINYINT(1) NOT NULL DEFAULT '0'

 

To use BOOL or BOOLEAN in MySQL we use TINYINT(1) data type.

With TINYINT '0' is false and '1' is true.

From MySQL documentation:

BOOL, BOOLEAN
These types are synonyms for TINYINT(1). A value of zero is considered false.
Nonzero values are considered true

Full MySQL documentation can be found here.

1. Database schema with boolean example

DROP DATABASE `db_user_tests`;
CREATE DATABASE `db_user_tests`;
USE `db_user_tests`;

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users`
(
	`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
    `is_user_removed` TINYINT(1) NOT NULL DEFAULT '0',
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci' ENGINE=InnoDB;

2. Adding boolean column to existing table example

MySQL query for add boolean column to existing table (alter table):

ALTER TABLE `users`
    ADD COLUMN `is_user_removed` TINYINT(1) NOT NULL DEFAULT '0';

References

  1. Numeric type overview - MySQL docs
  2. Integer type - MySQL docs
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more