为什么反引号在UPDATE查询的SET部分中不起作用(对于MySQL)?
如果按照以下语法正确编写,反引号将起作用-
update `yourTableName` set `yourTableName`.`yourColumnName`='yourNewValue' where yourCondition;
让我们首先创建一个-
mysql> create table `DemoTable_1401` -> ( -> Name varchar(20) -> );
使用insert在表中插入一些记录-
mysql> insert into `DemoTable_1401` values('Chris'); mysql> insert into `DemoTable_1401` values('David'); mysql> insert into `DemoTable_1401` values('Bob');
使用选择显示表中的所有记录-
mysql> select * from `DemoTable_1401`;
这将产生以下输出-
+-------+ | Name | +-------+ | Chris | | David | | Bob | +-------+ 3 rows in set (0.00 sec)
这是与反引号一起使用的查询-
mysql> update `DemoTable_1401` set `DemoTable_1401`.`Name`='Adam' where `Name`='David'; Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
mysql> select * from `DemoTable_1401`;
这将产生以下输出-
+-------+ | Name | +-------+ | Chris | | Adam | | Bob | +-------+ 3 rows in set (0.00 sec)