Why does the update command in MySQL insist on using slanted single quotes?

MySQLMySQLi Database

Use single quotes on string input value. If there is an identifier like table name or column name, then do not use single quotes (use backticks).

Let us first create a table −

mysql> create table DemoTable1552
   -> (
   -> `key` int,
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (0.82 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1552 values(101,'Chris');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1552 values(102,'David');
Query OK, 1 row affected (0.28 sec)
mysql> insert into DemoTable1552 values(103,'Mike');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1552;

This will produce the following output −

+------+-------+
| key  | Name  |
+------+-------+
|  101 | Chris |
|  102 | David |
|  103 | Mike  |
+------+-------+
3 rows in set (0.00 sec)

Here is how to use single quotes −

mysql> update DemoTable1552 set `key`=100 where Name='Chris';
Query OK, 1 row affected (0.20 sec)
Rows matched: 1  Changed: 1 Warnings: 0

Let us check the table records once again −

mysql> select * from DemoTable1552;

This will produce the following output −

+------+-------+
| key  | Name  |
+------+-------+
|  100 | Chris |
|  102 | David |
|  103 | Mike  |
+------+-------+
3 rows in set (0.00 sec)
raja
Published on 12-Dec-2019 06:27:13
Advertisements