Using Update statement with TINYINT in MySQL?


Let us first create a table. We have set one of the columns with type TINYINT −

mysql> create table DemoTable
   -> (
   -> EmployeeId int,
   -> isMarried tinyint
   -> );
Query OK, 0 rows affected (6.84 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(101,true);
Query OK, 1 row affected (1.94 sec)
mysql> insert into DemoTable values(102,false);
Query OK, 1 row affected (0.76 sec)
mysql> insert into DemoTable values(103,true);
Query OK, 1 row affected (1.14 sec)
mysql> insert into DemoTable values(104,true);
Query OK, 1 row affected (1.22 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+------------+----------+
| EmployeeId | isMarried|
+------------+----------+
|        101 |        1 |
|        102 |        0 |
|        103 |        1 |
|        104 |        1 |
+------------+----------+
4 rows in set (0.00 sec)

Here is the query to implement UPDATE statement with TINYINT −

mysql> update DemoTable
   -> set isMarried=false
   -> where EmployeeId=103;
Query OK, 1 row affected (1.24 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Let us check the table records once again −

mysql> select *from DemoTable;

This will produce the following output −

+------------+----------+
| EmployeeId | isMaried |
+------------+----------+
|        101 |        1 |
|        102 |        0 |
|        103 |        0 |
|        104 |        1 |
+------------+----------+
4 rows in set (0.00 sec)

Updated on: 12-Dec-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements