

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Updating boolean value in MySQL?
To update boolean value, you can use SET. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, isMarried boolean ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(isMarried) values(false); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(isMarried) values(true); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(isMarried) values(true); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(isMarried) values(false); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-----------+ | Id | isMarried | +----+-----------+ | 1 | 0 | | 2 | 1 | | 3 | 1 | | 4 | 0 | +----+-----------+ 4 rows in set (0.00 sec)
Following is the query to update boolean value −
mysql> update DemoTable set isMarried = !isMarried where Id=4; Query OK, 1 row affected (0.17 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us display the table records once again −
mysql> select *from DemoTable;
This will produce the following output. Here, we updated the boolean value for Id 4 −
+----+-----------+ | Id | isMarried | +----+-----------+ | 1 | 0 | | 2 | 1 | | 3 | 1 | | 4 | 1 | +----+-----------+ 4 rows in set (0.00 sec)
Look at the above sample output, the row with Id 4 has been updated.
- Related Questions & Answers
- Updating only a single column value in MySQL?
- Create a Boolean object from Boolean value in Java
- Java Program to convert boolean value to Boolean
- Updating a record in MySQL using NodeJS
- How to create boolean column in MySQL with false as default value?
- Updating default value of new column in SAP system
- Updating a MySQL table row column by appending a value from user defined variable?
- Select data and set value to boolean based on timestamp column in MySQL
- How to convert a boolean value to string value in JavaScript?
- Convert a specified value to an equivalent Boolean value in C#
- Updating last entry of a particular ID in MySQL
- Initialize the mask to homogeneous boolean array by passing in a scalar boolean value in Numpy
- Use boolean value to stop a thread in Java
- What is the Boolean value of undefined in JavaScript?
- How to convert a value into Boolean in JavaScript?
Advertisements