Keywords and Reserved Words

来源:互联网 发布:锁定4g网络 编辑:程序博客网 时间:2024/06/16 13:35
Keywords are words that have significance in SQL. Certain keywords, such as SELECT, DELETE, 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.

在sql中keywords是非常重要的字。特别的keywords,例如:select,delete,或者bigint 是保留的并要求特别对待的,当应用在表和字段时。function的名字也是如此。


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”:

非保留的keywords是被使用不需要引用他们的。保留的words被使用,需要你去引用他们

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

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是keywords但是非保留的,所以他们被使用时不需要引用。INTERVAL 是保留的keyword

mysql> CREATE TABLE `interval` (begin INT, end INT);

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:

keyword是保留,如果使用全名不需要引用,如下:

mysql> CREATE TABLE mydb.interval (begin INT, end INT);

Query OK, 0 rows affected (0.01 sec)


Names of built-in functions are permitted as identifiers but may require care to be used as such. For
example, COUNT is acceptable as a column name. However, by default, no whitespace is permitted in
function invocations between the function name and the following ( character. This requirement enables
the parser to distinguish whether the name is used in a function call or in nonfunction context. For further

details on recognition of function names, see Section 9.2.4, “Function Name Parsing and Resolution”.


The following table shows the keywords and reserved words in MySQL 5.6, along with changes to
individual words from version to version. Reserved keywords are marked with (R). In addition, _FILENAME

is reserved.


At some point, you might upgrade to a higher version, so it is a good idea to have a look at future reserved

words, too. You can find these in the manuals that cover higher versions of MySQL. Most of the reserved

words in the table are forbidden by standard SQL as column or table names (for example, GROUP). A few
are reserved because MySQL needs them and uses a yacc parser.