Can we perform MySQL UPDATE and change nothing in a table?

MySQLMySQLi Database

Yes, we can do that. Let us first create a table −

mysql> create table DemoTable(
   Id int
);
Query OK, 0 rows affected (1.02 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(201);
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable values(202);
Query OK, 1 row affected (0.09 sec)
mysql> insert into DemoTable values(290);
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values(301);
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   |
+------+
| 201  |
| 202  |
| 290  |
| 301  |
+------+
4 rows in set (0.00 sec)

Following is the query to perform MySQL UPDATE without changing anything −

mysql> update DemoTable set Id=Id where Id=290;
Query OK, 0 rows affected (0.08 sec)
Rows matched: 1 Changed: 0 Warnings: 0

Let us check table records once again −

mysql> select *from DemoTable;

This will produce the following output. It displays the same result −

+------+
| Id   |
+------+
| 201  |
| 202  |
| 290  |
| 301  |
+------+
4 rows in set (0.00 sec)
raja
Published on 27-Sep-2019 07:54:21
Advertisements