如何为与 MySql 中受保护关键字同名的表编写 SQL? [英] How can I write SQL for a table that shares the same name as a protected keyword in MySql?

查看:19
本文介绍了如何为与 MySql 中受保护关键字同名的表编写 SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的查询不会执行

mysql_query("SELECT * FROM order WHERE orderID = 102;");

它产生以下错误消息:

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 2 行的order WHERE orderID = 102"附近使用的正确语法

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 WHERE orderID = 102' at line 2

如何编写能够成功查询此表的 SQL?

How can I write SQL that will successfully query this table?

推荐答案

Order 是保留字.不要使用保留字作为表名或字段名;或将其包裹在转义字符中,例如 mysql 的 `.就我个人而言,我只是避免使用它们,因为从长远来看,它们通常会引起更多的头痛.

Order is a reserved word. Don't use reserved words as table or field names; or wrap it in the escape characters such as ` for mysql. Personally I just avoid using them as they generally cause more headache than they are worth in the long run.

示例:

mysql_query("SELECT * FROM `order` WHERE orderID = 102;");

更多信息 - 您可以在此处获得有关保留字的更多信息 https://dev.mysql.com/doc/refman/5.5/en/keywords.html

MORE INFO - you can get more info about reserved word here https://dev.mysql.com/doc/refman/5.5/en/keywords.html

这篇关于如何为与 MySql 中受保护关键字同名的表编写 SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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