适用于DELETE、FROM、WHERE的正确mySQL语法

3

我有一个数据库,其中有一张表格有18列,第二列被称为“desc”。我想删除所有在“desc”下具有特定值的行。我正在使用以下代码:

DELETE FROM items WHERE desc='Swap this note at any bank for the equivalent item.'

在PHPMYADMIN中使用此命令会导致以下错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='Swap this note at any bank for the equivalent item.'' at line 1

我已经仔细查看了,但似乎找不到我做错了什么。

MySQL版本为5.5,phpMyAdmin版本为3.4.5。

3个回答

5

在使用ORDER BY时,需要在desc 关键字周围使用反引号,因为它表示按降序排列:

DELETE FROM items 
WHERE `desc`='Swap this note at any bank for the equivalent item.' 

完美地工作了,我没有看到那个问题。感谢您的帮助。虽然语法正确,但我没有删除任何行,所以我要看看我哪里出了错。感谢您提供的解决方案。 - taylorthurlow
我之前用的是单引号,尽管你说的是反引号。现在可以正常工作了。感谢你提供的解决方案。 - taylorthurlow

0
注意反引号。desc是MySQL中的关键字。
DELETE FROM items WHERE `desc`='Swap this note at any bank for the equivalent item.'

0

desc 是 MySQL 中的 保留字

为了转义保留字,必须使用 反引号 ( ` )

DELETE FROM `items` 
WHERE `desc`='Swap this note at any bank for the equivalent item.' 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接