2017年7月
https://dev.mysql.com/doc/refman/5.7/en/keywords.html#
9.3关键字和保留字
关键字是在SQL中具有重要意义的词。某些关键字,如SELECT, DELETE或 BIGINT,被保留,需要用作标识符,例如表和列名特殊待遇。对于内置函数的名称也是如此。
非保留关键字作为标识符而不引用。如第9.2节“架构对象名称”中所述,如果引用了保留字,则可以将其保留为标识符:
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并且END是关键字但不保留,因此它们用作标识符不需要引用。INTERVAL是一个保留关键字,必须引用为标识符:
mysql> CREATE TABLE `interval` (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)
例外:在限定名称中的句点后面的单词必须是一个标识符,所以即使被保留,也不需要引用它:
mysql> CREATE TABLE mydb.interval (begin INT, end INT);
Query OK, 0 rows affected (0.01 sec)
允许内置函数的名称作为标识符,但可能需要谨慎使用。例如, COUNT作为列名可以接受。但是,默认情况下,在函数名和下一个( 字符之间的函数调用中不允许有空格。该要求使分析器能够区分名称是否在函数调用中使用,也可以在非功能上下文中使用。有关识别功能名称的更多详细信息,请参见 第9.2.4节“功能名称解析和分辨率”。
下表显示了MySQL 5.7中的关键字和保留字,以及从版本到版本的单个字的更改。保留关键字标有(R)。另外,_FILENAME是保留的。
在某些时候,您可能会升级到更高版本,所以看一下未来的保留字也是一个好主意。您可以在涵盖更高版本的MySQL的手册中找到这些。标准SQL作为列或表名称禁止表中的大多数保留字(例如, GROUP)。有一些是保留的,因为MySQL需要它们并使用yacc解析器。
表9.2 MySQL中的关键字和保留字5.7
ACCESSIBLE (R) | ACCOUNT[a] | ACTION |
---|---|---|
ADD (R) | AFTER | AGAINST |
AGGREGATE | ALGORITHM | ALL (R) |
ALTER (R) | ALWAYS[b] | ANALYSE |
ANALYZE (R) | AND (R) | ANY |
AS (R) | ASC (R) | ASCII |
ASENSITIVE (R) | AT | AUTOEXTEND_SIZE |
AUTO_INCREMENT | AVG | AVG_ROW_LENGTH |
BACKUP | BEFORE (R) | BEGIN |
BETWEEN (R) | BIGINT (R) | BINARY (R) |
BINLOG | BIT | BLOB (R) |
BLOCK | BOOL | BOOLEAN |
BOTH (R) | BTREE | BY (R) |
BYTE | CACHE | CALL (R) |
CASCADE (R) | CASCADED | CASE (R) |
CATALOG_NAME | CHAIN | CHANGE (R) |
CHANGED | CHANNEL[c] | CHAR (R) |
CHARACTER (R) | CHARSET | CHECK (R) |
CHECKSUM | CIPHER | CLASS_ORIGIN |
CLIENT | CLOSE | COALESCE |
CODE | COLLATE (R) | COLLATION |
COLUMN (R) | COLUMNS | COLUMN_FORMAT |
COLUMN_NAME | COMMENT | COMMIT |
COMMITTED | COMPACT | COMPLETION |
COMPRESSED | COMPRESSION[d] | CONCURRENT |
CONDITION (R) | CONNECTION | CONSISTENT |
CONSTRAINT (R) | CONSTRAINT_CATALOG | CONSTRAINT_NAME |
CONSTRAINT_SCHEMA | CONTAINS | CONTEXT |
CONTINUE (R) | CONVERT (R) | CPU |
CREATE (R) | CROSS (R) | CUBE |
CURRENT | CURRENT_DATE (R) | CURRENT_TIME (R) |
CURRENT_TIMESTAMP (R) | CURRENT_USER (R) | CURSOR (R) |
CURSOR_NAME | DATA | DATABASE (R) |
DATABASES (R) | DATAFILE | DATE |
DATETIME | DAY | DAY_HOUR (R) |
DAY_MICROSECOND (R) | DAY_MINUTE (R) | DAY_SECOND (R) |
DEALLOCATE | DEC (R) | DECIMAL (R) |
DECLARE (R) | DEFAULT (R) | DEFAULT_AUTH |
DEFINER | DELAYED (R) | DELAY_KEY_WRITE |
DELETE (R) | DESC (R) | DESCRIBE (R) |
DES_KEY_FILE | DETERMINISTIC (R) | DIAGNOSTICS |
DIRECTORY | DISABLE | DISCARD |
DISK | DISTINCT (R) | DISTINCTROW (R) |
DIV (R) | DO | DOUBLE (R) |
DROP (R) | DUAL (R) | DUMPFILE |
DUPLICATE | DYNAMIC | EACH (R) |
ELSE (R) | ELSEIF (R) | ENABLE |
ENCLOSED (R) | ENCRYPTION[e] | END |
ENDS | ENGINE | ENGINES |
ENUM | ERROR | ERRORS |
ESCAPE | ESCAPED (R) | EVENT |
EVENTS | EVERY | EXCHANGE |
EXECUTE | EXISTS (R) | EXIT (R) |
EXPANSION | EXPIRE | EXPLAIN (R) |
EXPORT | EXTENDED | EXTENT_SIZE |
FALSE (R) | FAST | FAULTS |
FETCH (R) | FIELDS | FILE |
FILE_BLOCK_SIZE[f] | FILTER[g] | FIRST |
FIXED | FLOAT (R) | FLOAT4 (R) |
FLOAT8 (R) | FLUSH | FOLLOWS[h] |
FOR (R) | FORCE (R) | FOREIGN (R) |
FORMAT | FOUND | FROM (R) |
FULL | FULLTEXT (R) | FUNCTION |
GENERAL | GENERATED[i] (R) | GEOMETRY |
GEOMETRYCOLLECTION | GET (R) | GET_FORMAT |
GLOBAL | GRANT (R) | GRANTS |
GROUP (R) | GROUP_REPLICATION[j] | HANDLER |
HASH | HAVING (R) | HELP |
HIGH_PRIORITY (R) | HOST | HOSTS |
HOUR | HOUR_MICROSECOND (R) | HOUR_MINUTE (R) |
HOUR_SECOND (R) | IDENTIFIED | IF (R) |
IGNORE (R) | IGNORE_SERVER_IDS | IMPORT |
IN (R) | INDEX (R) | INDEXES |
INFILE (R) | INITIAL_SIZE | INNER (R) |
INOUT (R) | INSENSITIVE (R) | INSERT (R) |
INSERT_METHOD | INSTALL | INSTANCE[k] |
INT (R) | INT1 (R) | INT2 (R) |
INT3 (R) | INT4 (R) | INT8 (R) |
INTEGER (R) | INTERVAL (R) | INTO (R) |
INVOKER | IO | IO_AFTER_GTIDS (R) |
IO_BEFORE_GTIDS (R) | IO_THREAD | IPC |
IS (R) | ISOLATION | ISSUER |
ITERATE (R) | JOIN (R) | JSON[l] |
KEY (R) | KEYS (R) | KEY_BLOCK_SIZE |
KILL (R) | LANGUAGE | LAST |
LEADING (R) | LEAVE (R) | LEAVES |
LEFT (R) | LESS | LEVEL |
LIKE (R) | LIMIT (R) | LINEAR (R) |
LINES (R) | LINESTRING | LIST |
LOAD (R) | LOCAL | LOCALTIME (R) |
LOCALTIMESTAMP (R) | LOCK (R) | LOCKS |
LOGFILE | LOGS | LONG (R) |
LONGBLOB (R) | LONGTEXT (R) | LOOP (R) |
LOW_PRIORITY (R) | MASTER | MASTER_AUTO_POSITION |
MASTER_BIND (R) | MASTER_CONNECT_RETRY | MASTER_DELAY |
MASTER_HEARTBEAT_PERIOD | MASTER_HOST | MASTER_LOG_FILE |
MASTER_LOG_POS | MASTER_PASSWORD | MASTER_PORT |
MASTER_RETRY_COUNT | MASTER_SERVER_ID | MASTER_SSL |
MASTER_SSL_CA | MASTER_SSL_CAPATH | MASTER_SSL_CERT |
MASTER_SSL_CIPHER | MASTER_SSL_CRL | MASTER_SSL_CRLPATH |
MASTER_SSL_KEY | MASTER_SSL_VERIFY_SERVER_CERT (R) | MASTER_TLS_VERSION[m] |
MASTER_USER | MATCH (R) | MAXVALUE (R) |
MAX_CONNECTIONS_PER_HOUR | MAX_QUERIES_PER_HOUR | MAX_ROWS |
MAX_SIZE | MAX_STATEMENT_TIME[n] | MAX_UPDATES_PER_HOUR |
MAX_USER_CONNECTIONS | MEDIUM | MEDIUMBLOB (R) |
MEDIUMINT (R) | MEDIUMTEXT (R) | MEMORY |
MERGE | MESSAGE_TEXT | MICROSECOND |
MIDDLEINT (R) | MIGRATE | MINUTE |
MINUTE_MICROSECOND (R) | MINUTE_SECOND (R) | MIN_ROWS |
MOD (R) | MODE | MODIFIES (R) |
MODIFY | MONTH | MULTILINESTRING |
MULTIPOINT | MULTIPOLYGON | MUTEX |
MYSQL_ERRNO | NAME | NAMES |
NATIONAL | NATURAL (R) | NCHAR |
NDB | NDBCLUSTER | NEVER[o] |
NEW | NEXT | NO |
NODEGROUP | NONBLOCKING[p] | NONE |
NOT (R) | NO_WAIT | NO_WRITE_TO_BINLOG (R) |
NULL (R) | NUMBER | NUMERIC (R) |
NVARCHAR | OFFSET | OLD_PASSWORD[q] |
ON (R) | ONE | ONLY |
OPEN | OPTIMIZE (R) | OPTIMIZER_COSTS[r] (R) |
OPTION (R) | OPTIONALLY (R) | OPTIONS |
OR (R) | ORDER (R) | OUT (R) |
OUTER (R) | OUTFILE (R) | OWNER |
PACK_KEYS | PAGE | PARSER |
PARSE_GCOL_EXPR[s] | PARTIAL | PARTITION (R) |
PARTITIONING | PARTITIONS | PASSWORD |
PHASE | PLUGIN | PLUGINS |
PLUGIN_DIR | POINT | POLYGON |
PORT | PRECEDES[t] | PRECISION (R) |
PREPARE | PRESERVE | PREV |
PRIMARY (R) | PRIVILEGES | PROCEDURE (R) |
PROCESSLIST | PROFILE | PROFILES |
PROXY | PURGE (R) | QUARTER |
QUERY | QUICK | RANGE (R) |
READ (R) | READS (R) | READ_ONLY |
READ_WRITE (R) | REAL (R) | REBUILD |
RECOVER | REDOFILE | REDO_BUFFER_SIZE |
REDUNDANT | REFERENCES (R) | REGEXP (R) |
RELAY | RELAYLOG | RELAY_LOG_FILE |
RELAY_LOG_POS | RELAY_THREAD | RELEASE (R) |
RELOAD | REMOVE | RENAME (R) |
REORGANIZE | REPAIR | REPEAT (R) |
REPEATABLE | REPLACE (R) | REPLICATE_DO_DB[u] |
REPLICATE_DO_TABLE[v] | REPLICATE_IGNORE_DB[w] | REPLICATE_IGNORE_TABLE[x] |
REPLICATE_REWRITE_DB[y] | REPLICATE_WILD_DO_TABLE[z] | REPLICATE_WILD_IGNORE_TABLE[aa] |
REPLICATION | REQUIRE (R) | RESET |
RESIGNAL (R) | RESTORE | RESTRICT (R) |
RESUME | RETURN (R) | RETURNED_SQLSTATE |
RETURNS | REVERSE | REVOKE (R) |
RIGHT (R) | RLIKE (R) | ROLLBACK |
ROLLUP | ROTATE[ab] | ROUTINE |
ROW | ROWS | ROW_COUNT |
ROW_FORMAT | RTREE | SAVEPOINT |
SCHEDULE | SCHEMA (R) | SCHEMAS (R) |
SCHEMA_NAME | SECOND | SECOND_MICROSECOND (R) |
SECURITY | SELECT (R) | SENSITIVE (R) |
SEPARATOR (R) | SERIAL | SERIALIZABLE |
SERVER | SESSION | SET (R) |
SHARE | SHOW (R) | SHUTDOWN |
SIGNAL (R) | SIGNED | SIMPLE |
SLAVE | SLOW | SMALLINT (R) |
SNAPSHOT | SOCKET | SOME |
SONAME | SOUNDS | SOURCE |
SPATIAL (R) | SPECIFIC (R) | SQL (R) |
SQLEXCEPTION (R) | SQLSTATE (R) | SQLWARNING (R) |
SQL_AFTER_GTIDS | SQL_AFTER_MTS_GAPS | SQL_BEFORE_GTIDS |
SQL_BIG_RESULT (R) | SQL_BUFFER_RESULT | SQL_CACHE |
SQL_CALC_FOUND_ROWS (R) | SQL_NO_CACHE | SQL_SMALL_RESULT (R) |
SQL_THREAD | SQL_TSI_DAY | SQL_TSI_HOUR |
SQL_TSI_MINUTE | SQL_TSI_MONTH | SQL_TSI_QUARTER |
SQL_TSI_SECOND | SQL_TSI_WEEK | SQL_TSI_YEAR |
SSL (R) | STACKED | START |
STARTING (R) | STARTS | STATS_AUTO_RECALC |
STATS_PERSISTENT | STATS_SAMPLE_PAGES | STATUS |
STOP | STORAGE | STORED[ac] (R) |
STRAIGHT_JOIN (R) | STRING | SUBCLASS_ORIGIN |
SUBJECT | SUBPARTITION | SUBPARTITIONS |
SUPER | SUSPEND | SWAPS |
SWITCHES | TABLE (R) | TABLES |
TABLESPACE | TABLE_CHECKSUM | TABLE_NAME |
TEMPORARY | TEMPTABLE | TERMINATED (R) |
TEXT | THAN | THEN (R) |
TIME | TIMESTAMP | TIMESTAMPADD |
TIMESTAMPDIFF | TINYBLOB (R) | TINYINT (R) |
TINYTEXT (R) | TO (R) | TRAILING (R) |
TRANSACTION | TRIGGER (R) | TRIGGERS |
TRUE (R) | TRUNCATE | TYPE |
TYPES | UNCOMMITTED | UNDEFINED |
UNDO (R) | UNDOFILE | UNDO_BUFFER_SIZE |
UNICODE | UNINSTALL | UNION (R) |
UNIQUE (R) | UNKNOWN | UNLOCK (R) |
UNSIGNED (R) | UNTIL | UPDATE (R) |
UPGRADE | USAGE (R) | USE (R) |
USER | USER_RESOURCES | USE_FRM |
USING (R) | UTC_DATE (R) | UTC_TIME (R) |
UTC_TIMESTAMP (R) | VALIDATION[ad] | VALUE |
VALUES (R) | VARBINARY (R) | VARCHAR (R) |
VARCHARACTER (R) | VARIABLES | VARYING (R) |
VIEW | VIRTUAL[ae] (R) | WAIT |
WARNINGS | WEEK | WEIGHT_STRING |
WHEN (R) | WHERE (R) | WHILE (R) |
WITH (R) | WITHOUT[af] | WORK |
WRAPPER | WRITE (R) | X509 |
XA | XID[ag] | XML |
XOR (R) | YEAR | YEAR_MONTH (R) |
ZEROFILL (R) |
[a]ACCOUNT:添加在5.7.6(非保留)
[b]ALWAYS:加入5.7.6(非保留)
[c]CHANNEL:加入5.7.6(非保留)
[d]COMPRESSION:加入5.7.8(非保留)
[e]ENCRYPTION:加入5.7.11(非保留)
[f]FILE_BLOCK_SIZE:加入5.7.6(非保留)
[g]FILTER:加入5.7.3(非保留)
[h]FOLLOWS:加入5.7.2(非保留)
[i]GENERATED:加入5.7.6(保留)
[j]GROUP_REPLICATION:加入5.7.6(非保留)
[k]INSTANCE:加入5.7.11(非保留)
[l]JSON:加入5.7.8(非保留)
[m]MASTER_TLS_VERSION:加入5.7.10(非保留)
[n]MAX_STATEMENT_TIME:加入5.7.4(非保留); 在5.7.8中删除
[o]NEVER:加入5.7.4(非保留)
[p]NONBLOCKING:在5.7.6中删除
[q]OLD_PASSWORD:在5.7.5中删除
[r]OPTIMIZER_COSTS:加入5.7.5(保留)
[s]PARSE_GCOL_EXPR:加入5.7.6(保留); 在5.7.8中没有保留
[t]PRECEDES:添加在5.7.2(非保留)
[u]REPLICATE_DO_DB:添加在5.7.3(非保留)
[v]REPLICATE_DO_TABLE:添加在5.7.3(非保留)
[w]REPLICATE_IGNORE_DB:加入5.7.3(非保留)
[x]REPLICATE_IGNORE_TABLE:添加在5.7.3(非保留)
[y]REPLICATE_REWRITE_DB:添加在5.7.3(非保留)
[z]REPLICATE_WILD_DO_TABLE:添加在5.7.3(非保留)
[aa]REPLICATE_WILD_IGNORE_TABLE:添加在5.7.3(非保留)
[ab]ROTATE:添加在5.7.11(非保留)
[ac]STORED:添加在5.7.6(保留)
[ad]VALIDATION:加入5.7.5(非保留)
[ae]VIRTUAL:加入5.7.6(保留)
[af]WITHOUT:加入5.7.5(非保留)
[ag]XID:加入5.7.5(非保留)
下表显示了MySQL 5.7中添加的关键字和保留字。保留关键字标有(R)。
表9.3 MySQL中添加的关键字和保留字5.7与MySQL 5.6相比
ACCOUNT | ALWAYS | CHANNEL |
---|---|---|
COMPRESSION | ENCRYPTION | FILE_BLOCK_SIZE |
FILTER | FOLLOWS | GENERATED (R) |
GROUP_REPLICATION | INSTANCE | JSON |
MASTER_TLS_VERSION | NEVER | OPTIMIZER_COSTS (R) |
PARSE_GCOL_EXPR | PRECEDES | REPLICATE_DO_DB |
REPLICATE_DO_TABLE | REPLICATE_IGNORE_DB | REPLICATE_IGNORE_TABLE |
REPLICATE_REWRITE_DB | REPLICATE_WILD_DO_TABLE | REPLICATE_WILD_IGNORE_TABLE |
ROTATE | STACKED | STORED (R) |
VALIDATION | VIRTUAL (R) | WITHOUT |
XID |
下表显示了MySQL 5.7中删除的关键字和保留字。保留关键字标有(R)。
表9.4 MySQL 5.7中删除的关键字和保留字与MySQL 5.6相比
| |
---|---|---
OLD_PASSWORD| |