Why do backticks won’t work in the SET part of an UPDATE query (for MySQL)?


Backticks would work if written correctly as in the below syntax −

update `yourTableName` set `yourTableName`.`yourColumnName`='yourNewValue' where yourCondition;

Let us first create a −

mysql> create table `DemoTable_1401`
   -> (
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (0.52 sec)

Insert some records in the table using insert −

mysql> insert into `DemoTable_1401` values('Chris');
Query OK, 1 row affected (0.16 sec)
mysql> insert into `DemoTable_1401` values('David');
Query OK, 1 row affected (0.10 sec)
mysql> insert into `DemoTable_1401` values('Bob');
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select −

mysql> select * from `DemoTable_1401`;

This will produce the following output −

+-------+
| Name  |
+-------+
| Chris |
| David |
| Bob   |
+-------+
3 rows in set (0.00 sec)

Here is the query to work with backticks −

mysql> update `DemoTable_1401` set `DemoTable_1401`.`Name`='Adam' where `Name`='David';
Query OK, 1 row affected (0.15 sec)
Rows matched: 1  Changed: 1 Warnings: 0

Let us check the table records once again −

mysql> select * from `DemoTable_1401`;

This will produce the following output −

+-------+
| Name  |
+-------+
| Chris |
| Adam  |
| Bob   |
+-------+
3 rows in set (0.00 sec)

Updated on: 11-Nov-2019

98 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements