mysql查询关键字_在查询中使用MySQL关键字?

bd96500e110b49cbb3cd949968f18be7.png

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.

解决方案

Use backticks:

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)

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值