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

在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)

 

转载于:https://www.cnblogs.com/nemowang1996/p/10749214.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值