【问题标题】:Proper mySQL syntax for DELETE, FROM, WHERE用于 DELETE、FROM、WHERE 的正确 mySQL 语法
【发布时间】:2012-02-21 22:35:47
【问题描述】:

我有一个包含 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。

【问题讨论】:

    标签: php mysql sql database phpmyadmin


    【解决方案1】:

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

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

    【讨论】:

    • 工作得很好,我没看到。谢谢你的帮助。我没有删除任何行,但语法很好,所以我要看看我做错了什么。感谢您的解决方案。
    • 我使用了一个撇号,尽管你说反勾号。现在工作正常。感谢您的解决方案。
    【解决方案2】:

    注意后面的记号。 desc 是 MySQL 中的关键字

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

    【讨论】:

      【解决方案3】:

      desc 是 MySQL 中的 RESERVED WORD

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-08-15
        • 2014-01-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多