首页 > 数据库技术 > 详细

MySQL保留字冲突 关键词:保留字, 关键字

时间:2019-04-22 11:58:57      阅读:278      评论:0      收藏:0      [点我收藏+]

在Mysql中,当表名或字段名乃至数据库名和保留字冲突时,在sql语句里可以用撇号`(Tab键上方的按键)括起来。

注意,只有保留字需要``括起来,非保留字的关键字不需要。

MySQL 8.0 官方文档:https://dev.mysql.com/doc/refman/8.0/en/keywords.html

Keywords are words that have significance in SQL. Certain keywords, such as SELECTDELETE, or BIGINT, are reserved and require special treatment for use as identifiers such as table and column names. This may also be true for the names of built-in functions.

Nonreserved keywords are permitted as identifiers without quoting. Reserved words are permitted as identifiers if you quote them as described in Section 9.2, “Schema Object Names”:

 

关键词是SQL中有特定意义的词。一些关键词,例如select, delete, bigint,属于保留字,在用作例如表名和列名的时候需要特殊对待。对于内置函数的名称也是如此。

非保留字在用作标识符的时候不需要使用``包含起来。

 

1 mysql> CREATE TABLE interval (begin INT, end INT);
2 ERROR 1064 (42000): You have an error in your SQL syntax ...
3 near interval (begin INT, end INT)

BEGIN and END are keywords but not reserved, so their use as identifiers does not require quoting. INTERVAL is a reserved keyword and must be quoted to be used as an identifier:

begin和end都是关键词但不是保留字,所以使用它们用作标识符的时候不需要``引用。而interval属于保留关键词,所以在用作标识符的时候必须使用``引用:

1 mysql> CREATE TABLE `interval` (begin INT, end INT);
2 Query OK, 0 rows affected (0.01 sec)

Exception: A word that follows a period in a qualified name must be an identifier, so it need not be quoted even if it is reserved:

例外:限定名中跟在句点后面的单词一定是标识符,因此即使它是保留字,也不需要``引用:

1 mysql> CREATE TABLE mydb.interval (begin INT, end INT);
2 Query OK, 0 rows affected (0.01 sec)

 

MySQL保留字冲突 关键词:保留字, 关键字

原文:https://www.cnblogs.com/nemowang1996/p/10749214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!