Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of boolean (type = bit(1)) in Mysql Workbench

How can I edit the value of a boolean (type = bit(1)) in Mysql Workbench's result grid of a table?

If I set it to 1 or 0 I get the error :

ERROR 1406: 1406: Data too long for column 'enabled' at row 1

like image 596
johanvs Avatar asked Mar 15 '17 08:03

johanvs


People also ask

How do you set a boolean to true in MySQL?

You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).

How do you declare a boolean variable in MySQL?

MySQL does not contain built-in Boolean or Bool data type. They provide a TINYINT data type instead of Boolean or Bool data types. MySQL considered value zero as false and non-zero value as true. If you want to use Boolean literals, use true or false that always evaluates to 0 and 1 value.

How do you give a boolean value in SQL?

You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.

Is there a boolean data type in MySQL?

MySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.


2 Answers

Write b'1' for true, and b'0' for false.

like image 177
johanvs Avatar answered Sep 20 '22 10:09

johanvs


You can also use true false keywords for value where true = 1 and false = 0.

MySQL Workbench Version: 6.3.4.0

UPDATE

Mysql Server Version: 5.6.27-log

enter image description here

like image 30
Bahadir Tasdemir Avatar answered Sep 22 '22 10:09

Bahadir Tasdemir