代码之家  ›  专栏  ›  技术社区  ›  rhodesjason

为什么这个SQL更新查询不起作用?

  •  5
  • rhodesjason  · 技术社区  · 16 年前

    我对SQL很了解,但我一定错过了一些非常愚蠢的东西。此更新查询不断抛出错误。查询是:

    UPDATE pages SET 'order' = 1 WHERE id = 19
    

    我得到的错误是一般错误:

    #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 '"order" = 2 WHERE id = 19' at line 1 
    

    我把订单用引号括起来是因为 ORDER 是保留的SQL字。我错过了什么?

    8 回复  |  直到 9 年前
        1
  •  9
  •   Tobias    16 年前

    如果使用MySQL,查询应如下所示:

    UPDATE `pages` SET `order`=1 WHERE `id`=19
    
        2
  •  3
  •   Ken    16 年前

    看起来像是MySQL错误消息。MySQL不使用backticks(`)来转义吗?

        3
  •  3
  •   worldofjr lola_the_coding_girl    9 年前
    UPDATE pages SET [order] = 1 WHERE id = 19
    

    Nevemind MySQL公司

        4
  •  1
  •   Hans Kesting    16 年前

    不要使用引号,使用[order](或者您的sql版本用于转义的任何东西)。对于常规引号,它被视为字符串文本,这在这里是不允许的。

        5
  •  0
  •   worldofjr lola_the_coding_girl    9 年前

    UPDATE pages SET order = '1'
    WHERE id = 19
    
        6
  •  0
  •   worldofjr lola_the_coding_girl    9 年前

    order 是在中使用的保留字 ORDER BY .

        7
  •  0
  •   worldofjr lola_the_coding_girl    9 年前

    您需要从查询中的列名规范中删除单引号

    UPDATE pages SET order = 1 WHERE id = 19 ; 
    
        8
  •  0
  •   worldofjr lola_the_coding_girl    9 年前

    最简单的答案是;

    UPDATE pages SET pages.order = 1 WHERE id = 19 ;