EN
MySQL - boolean data type
2 points
Simplest solution:
xxxxxxxxxx
1
`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 forTINYINT(1)
. A value of zero is consideredfalse
.
Nonzero values are consideredtrue
Full MySQL documentation can be found here.
xxxxxxxxxx
1
DROP DATABASE `db_user_tests`;
2
CREATE DATABASE `db_user_tests`;
3
USE `db_user_tests`;
4
5
DROP TABLE IF EXISTS `users`;
6
CREATE TABLE `users`
7
(
8
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
9
`is_user_removed` TINYINT(1) NOT NULL DEFAULT '0',
10
PRIMARY KEY (`id`)
11
)
12
COLLATE='utf8_general_ci' ENGINE=InnoDB;
MySQL query for add boolean column to existing table (alter table):
xxxxxxxxxx
1
ALTER TABLE `users`
2
ADD COLUMN `is_user_removed` TINYINT(1) NOT NULL DEFAULT '0';