如何在SQL中使用保留字作为表名? [英] How to use a reserved word in SQL as a table name?
问题描述
使用此查询时:
INSERT INTO order (order_quantity)
VALUES ('50')
我遇到错误:
您的SQL语法有错误;检查手册 对应于您的MariaDB服务器版本,以使用正确的语法 在第146行的'order(order_quantity)VALUES('50')'附近
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'order (order_quantity) VALUES('50')' at line 146
我的查询出了什么问题?
What's wrong with my query?
推荐答案
不建议将保留字用作数据库,表,列,变量或其他对象名.如果您希望使用保留字作为ANSI标准语法中的对象名称,则必须将其括在双引号中,以使Relational Engine(无论是哪个)都可以将该词用作对象,而不是将其用作对象.给定上下文中的关键字.
Reserved words are not recommended for use as database, table, column, variable or other object names. If you desire to use a reserved word is used as an object name in ANSI standard syntax, it must be enclosed in double-quotes to allow the Relational Engine (whichever that one is) that the word is being used as an object and not as a keyword in the given context.
以下是一些特定于不同SQL引擎的示例:
Here are some examples specific to different SQL engines:
order
是一个SQL关键字,用于对结果(ORDER BY ...
)进行排序
order
is a SQL Keyword, used to sort results (ORDER BY ...
)
如果您使用的是 MySQL , a>或 Maria DB
INSERT INTO `order` (order_quantity) VALUES ('50');
INSERT INTO "order" (order_quantity) VALUES ('50');
例如,除了常识之外,没有什么阻止您使用表INTO
具有列VALUE(42)
In example, nothing (but common sense) prevents you from creating a database named INSERT
with a table INTO
having a column VALUE(42)
是的,此查询有效:
USE [INSERT];
SELECT [INTO].[VALUE(42)] FROM [INTO];
这篇关于如何在SQL中使用保留字作为表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!