在查询中使用MySQL关键字? [英] Using MySQL keywords in a query?

查看:390
本文介绍了在查询中使用MySQL关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用其中的关键字进行MySQL查询.有什么办法可以封装这些关键字,以便无论如何我都能使用它们?

I am trying to make a MySQL query with keywords in it. Is there any way to encapsulate these keywords so that I can use them anyway?

以下是无法执行的查询:

Here's the query that won't execute:

INSERT INTO PendingPasswordRecovery (key, userID, TimeModified, TimeCreated, TimeDeleted, IsDeleted) VALUES ('test123', 1, '2011-07-26 16:26:56', '2011-07-26 16:26:56', '1000-01-01 00:00:00', false)

您可能已经猜到了,键"是我在查询中使用的关键字,但不幸的是,它也是我要使用的列的名称.

As you have probably guessed already, "key" is the keyword that I am using in the query, and it is unfortunately also the name of the column I want to use.

推荐答案

使用反引号:

INSERT INTO PendingPasswordRecovery (`key`, `userID`, `TimeModified`, `TimeCreated`, `TimeDeleted`, `IsDeleted`) VALUES ('test123', 1, '2011-07-26 16:26:56', '2011-07-26 16:26:56', '1000-01-01 00:00:00', false)

我已经在所有列名中添加了反引号,但是您可以为关键字执行此操作.反引号称为"标识符引号字符".有关更多信息,请参见: http://dev.mysql.com /doc/refman/5.1/en/reserved-words.html

I have added backticks to all column names but you could just do it for the keyword. The backticks are called "identifier quote characters". For more information, see: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html and http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

这篇关于在查询中使用MySQL关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆