简体   繁体   English

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

[英]Why doesn't this SQL UPDATE query work?

I know SQL well but I must be missing something really dumb here. 我很熟悉SQL,但我必须在这里找到一些非常愚蠢的东西。 This update query keeps throwing an error. 此更新查询不断抛出错误。 The query is: 查询是:

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

The table definitely has a column for order, and it has a record with the ID of 19. The order column is not unique. 该表肯定有一个订单列,它有一个ID为19的记录。订单列不是唯一的。

The error I get is the generic one: 我得到的错误是通用错误:

#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 

I've enclosed order in quotation marks because ORDER is a reserved SQL word. 我在引号中包含了顺序,因为ORDER是一个保留的SQL字。 What am I missing? 我错过了什么?

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

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

That looks like a MySQL error message. 这看起来像MySQL错误消息。 Doesn't MySQL use backticks (`) for escaping? MySQL是否使用反引号(`)进行转义?

UPDATE pages SET [order] = 1 WHERE id = 19

Nevemind MySQL

don't use quotes, use [order] (or whatever your sql version uses for escaping). 不要使用引号,使用[order](或者你的sql版本用于转义的任何内容)。 With the regular quotes it is seen as a string literal, which is not allowed here. 使用常规引号时,它被视为字符串文字,这里不允许这样做。

The simplest answer is; 最简单的答案是;

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

That should do the trick. 这应该够了吧。

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

UPDATE pages SET order = 1 WHERE id = 19 ; 

order is a reserved word used in ORDER BY . orderORDER BY使用的保留字。

Use backticks (`) (as Ken said). 使用反引号(`)(如肯所说)。

I think the query should be; 我认为查询应该是;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM