关键字

本文介绍 TiDB 的关键字,对保留字和非保留字作出区分,并汇总所有的关键字以供查询使用。

关键字是 SQL 语句中具有特殊含义的单词,例如 SELECTUPDATEDELETE 等等。它们之中有的能够直接作为标识符,被称为非保留关键字(简称非保留字),但有需要经过特殊处理才能作为标识符的字,被称为保留关键字(简称保留字)。但是,也存在一些特殊的非保留关键字,有时候可能也需要进行特殊处理,推荐你将它们当作保留关键字处理。

对于保留字,必须使用反引号包裹,才能作为标识符被使用。例如:

CREATE TABLE select (a INT);
ERROR 1105 (HY000): line 0 column 19 near " (a INT)" (total length 27)
CREATE TABLE `select` (a INT);
Query OK, 0 rows affected (0.09 sec)

而非保留字则不需要反引号也能直接作为标识符。例如 BEGINEND 是非保留字,以下语句能够正常执行:

CREATE TABLE `select` (BEGIN int, END int);
Query OK, 0 rows affected (0.09 sec)

有一种特殊情况,如果使用了限定符 .,那么也不需要用反引号:

CREATE TABLE test.select (BEGIN int, END int);
Query OK, 0 rows affected (0.08 sec)

TiDB 从 v7.6.0 开始提供 INFORMATION_SCHEMA.KEYWORDS 表,可以用于查询 TiDB 中所有的关键字。

关键字列表

下表列出了 TiDB 中所有的关键字。其中保留字用 (R) 来标识。窗口函数的保留字用 (R-Window) 来标识。需要用反引号 ` 包裹的特殊非保留字用 (S) 来标识。

A
  • ACCOUNT
  • ACTION
  • ADD (R)
  • ADMIN
  • ADVISE
  • AFTER
  • AGAINST
  • AGO
  • ALGORITHM
  • ALL (R)
  • ALTER (R)
  • ALWAYS
  • ANALYZE (R)
  • AND (R)
  • ANY
  • ARRAY (R)
  • AS (R)
  • ASC (R)
  • ASCII
  • ATTRIBUTE
  • ATTRIBUTES
  • AUTO_ID_CACHE
  • AUTO_INCREMENT
  • AUTO_RANDOM
  • AUTO_RANDOM_BASE
  • AVG
  • AVG_ROW_LENGTH
B
  • BACKEND
  • BACKUP
  • BACKUPS
  • BATCH
  • BDR
  • BEGIN
  • BERNOULLI
  • BETWEEN (R)
  • BIGINT (R)
  • BINARY (R)
  • BINDING
  • BINDINGS
  • BINDING_CACHE
  • BINLOG
  • BIT
  • BLOB (R)
  • BLOCK
  • BOOL
  • BOOLEAN
  • BOTH (R)
  • BTREE
  • BUCKETS
  • BUILTINS
  • BY (R)
  • BYTE
C
  • CACHE
  • CALIBRATE
  • CALL (R)
  • CANCEL
  • CAPTURE
  • CARDINALITY
  • CASCADE (R)
  • CASCADED
  • CASE (R)
  • CAUSAL
  • CHAIN
  • CHANGE (R)
  • CHAR (R)
  • CHARACTER (R)
  • CHARSET
  • CHECK (R)
  • CHECKPOINT
  • CHECKSUM
  • CIPHER
  • CLEANUP
  • CLIENT
  • CLIENT_ERRORS_SUMMARY
  • CLOSE
  • CLUSTER
  • CLUSTERED
  • CMSKETCH
  • COALESCE
  • COLLATE (R)
  • COLLATION
  • COLUMN (R)
  • COLUMN_FORMAT
  • COLUMN_STATS_USAGE
  • COLUMNS
  • COMMENT
  • COMMIT
  • COMMITTED
  • COMPACT
  • COMPRESSED
  • COMPRESSION
  • CONCURRENCY
  • CONFIG
  • CONNECTION
  • CONSISTENCY
  • CONSISTENT
  • CONSTRAINT (R)
  • CONTEXT
  • CONTINUE (R)
  • CONVERT (R)
  • CORRELATION
  • CPU
  • CREATE (R)
  • CROSS (R)
  • CSV_BACKSLASH_ESCAPE
  • CSV_DELIMITER
  • CSV_HEADER
  • CSV_NOT_NULL
  • CSV_NULL
  • CSV_SEPARATOR
  • CSV_TRIM_LAST_SEPARATORS
  • CUME_DIST (R-Window)
  • CURRENT
  • CURRENT_DATE (R)
  • CURRENT_ROLE (R)
  • CURRENT_TIME (R)
  • CURRENT_TIMESTAMP (R)
  • CURRENT_USER (R)
  • CURSOR (R)
  • CYCLE
D
  • DATA
  • DATABASE (R)
  • DATABASES (R)
  • DATE
  • DATETIME
  • DAY
  • DAY_HOUR (R)
  • DAY_MICROSECOND (R)
  • DAY_MINUTE (R)
  • DAY_SECOND (R)
  • DDL
  • DEALLOCATE
  • DECIMAL (R)
  • DECLARE
  • DEFAULT (R)
  • DEFINER
  • DELAY_KEY_WRITE
  • DELAYED (R)
  • DELETE (R)
  • DENSE_RANK (R-Window)
  • DEPENDENCY
  • DEPTH
  • DESC (R)
  • DESCRIBE (R)
  • DIGEST
  • DIRECTORY
  • DISABLE
  • DISABLED
  • DISCARD
  • DISK
  • DISTINCT (R)
  • DISTINCTROW (R)
  • DIV (R)
  • DO
  • DOUBLE (R)
  • DRAINER
  • DROP (R)
  • DRY
  • DUAL (R)
  • DUPLICATE
  • DYNAMIC
E
  • ELSE (R)
  • ELSEIF (R)
  • ENABLE
  • ENABLED
  • ENCLOSED (R)
  • ENCRYPTION
  • END
  • ENFORCED
  • ENGINE
  • ENGINES
  • ENUM
  • ERROR
  • ERRORS
  • ESCAPE
  • ESCAPED (R)
  • EVENT
  • EVENTS
  • EVOLVE
  • EXCEPT (R)
  • EXCHANGE
  • EXCLUSIVE
  • EXECUTE
  • EXISTS (R)
  • EXIT (R)
  • EXPANSION
  • EXPIRE
  • EXPLAIN (R)
  • EXTENDED
F
  • FAILED_LOGIN_ATTEMPTS
  • FALSE (R)
  • FAULTS
  • FETCH (R)
  • FIELDS
  • FILE
  • FIRST
  • FIRST_VALUE (R-Window)
  • FIXED
  • FLOAT (R)
  • FLOAT4 (R)
  • FLOAT8 (R)
  • FLUSH
  • FOLLOWING
  • FOR (R)
  • FORCE (R)
  • FOREIGN (R)
  • FORMAT
  • FOUND
  • FROM (R)
  • FULL
  • FULLTEXT (R)
  • FUNCTION
G
  • GENERAL
  • GENERATED (R)
  • GLOBAL
  • GRANT (R)
  • GRANTS
  • GROUP (R)
  • GROUPS (R-Window)
H
  • HANDLER
  • HASH
  • HAVING (R)
  • HELP
  • HIGH_PRIORITY (R)
  • HISTOGRAM
  • HISTOGRAMS_IN_FLIGHT
  • HISTORY
  • HOSTS
  • HOUR
  • HOUR_MICROSECOND (R)
  • HOUR_MINUTE (R)
  • HOUR_SECOND (R)
  • HYPO
I
  • IDENTIFIED
  • IF (R)
  • IGNORE (R)
  • ILIKE (R)
  • IMPORT
  • IMPORTS
  • IN (R)
  • INCREMENT
  • INCREMENTAL
  • INDEX (R)
  • INDEXES
  • INFILE (R)
  • INNER (R)
  • INOUT (R)
  • INSERT (R)
  • INSERT_METHOD
  • INSTANCE
  • INT (R)
  • INT1 (R)
  • INT2 (R)
  • INT3 (R)
  • INT4 (R)
  • INT8 (R)
  • INTEGER (R)
  • INTERSECT (R)
  • INTERVAL (R)
  • INTO (R)
  • INVISIBLE
  • INVOKER
  • IO
  • IPC
  • IS (R)
  • ISOLATION
  • ISSUER
  • ITERATE (R)
J
  • JOB
  • JOBS
  • JOIN (R)
  • JSON
K
  • KEY (R)
  • KEYS (R)
  • KEY_BLOCK_SIZE
  • KILL (R)
L
  • LABELS
  • LAG (R-Window)
  • LANGUAGE
  • LAST
  • LAST_BACKUP
  • LAST_VALUE (R-Window)
  • LASTVAL
  • LEAD (R-Window)
  • LEADING (R)
  • LEAVE (R)
  • LEFT (R)
  • LESS
  • LEVEL
  • LIKE (R)
  • LIMIT (R)
  • LINEAR (R)
  • LINES (R)
  • LIST
  • LOAD (R)
  • LOCAL
  • LOCALTIME (R)
  • LOCALTIMESTAMP (R)
  • LOCATION
  • LOCK (R)
  • LOCKED
  • LOGS
  • LONG (R)
  • LONGBLOB (R)
  • LONGTEXT (R)
  • LOW_PRIORITY (R)
M
  • MASTER
  • MATCH (R)
  • MAXVALUE (R)
  • MAX_CONNECTIONS_PER_HOUR
  • MAX_IDXNUM
  • MAX_MINUTES
  • MAX_QUERIES_PER_HOUR
  • MAX_ROWS
  • MAX_UPDATES_PER_HOUR
  • MAX_USER_CONNECTIONS
  • MB
  • MEDIUMBLOB (R)
  • MEDIUMINT (R)
  • MEDIUMTEXT (R)
  • MEMBER
  • MEMORY
  • MERGE
  • MICROSECOND
  • MIDDLEINT (R)
  • MINUTE
  • MINUTE_MICROSECOND (R)
  • MINUTE_SECOND (R)
  • MINVALUE
  • MIN_ROWS
  • MOD (R)
  • MODE
  • MODIFY
  • MONTH
N
  • NAMES
  • NATIONAL
  • NATURAL (R)
  • NCHAR
  • NEVER
  • NEXT
  • NEXTVAL
  • NO
  • NOCACHE
  • NOCYCLE
  • NODEGROUP
  • NODE_ID
  • NODE_STATE
  • NOMAXVALUE
  • NOMINVALUE
  • NONCLUSTERED
  • NONE
  • NOT (R)
  • NOWAIT
  • NO_WRITE_TO_BINLOG (R)
  • NTH_VALUE (R-Window)
  • NTILE (R-Window)
  • NULL (R)
  • NULLS
  • NUMERIC (R)
  • NVARCHAR
O
  • OF (R)
  • OFF
  • OFFSET
  • OLTP_READ_ONLY
  • OLTP_READ_WRITE
  • OLTP_WRITE_ONLY
  • ON (R)
  • ON_DUPLICATE
  • ONLINE
  • ONLY
  • OPEN
  • OPTIMISTIC
  • OPTIMIZE (R)
  • OPTION (R)
  • OPTIONAL
  • OPTIONALLY (R)
  • OR (R)
  • ORDER (R)
  • OUT (R)
  • OUTER (R)
  • OUTFILE (R)
  • OVER (R-Window)
P
  • PACK_KEYS
  • PAGE
  • PARSER
  • PARTIAL
  • PARTITION (R)
  • PARTITIONING
  • PARTITIONS
  • PASSWORD
  • PASSWORD_LOCK_TIME
  • PAUSE
  • PERCENT
  • PERCENT_RANK (R-Window)
  • PER_DB
  • PER_TABLE
  • PESSIMISTIC
  • PLACEMENT (S)
  • PLUGINS
  • POINT
  • POLICY
  • PRECEDING
  • PRECISION (R)
  • PREPARE
  • PRESERVE
  • PRE_SPLIT_REGIONS
  • PRIMARY (R)
  • PRIVILEGES
  • PROCEDURE (R)
  • PROCESS
  • PROCESSLIST
  • PROFILE
  • PROFILES
  • PROXY
  • PUMP
  • PURGE
Q
  • QUARTER
  • QUERIES
  • QUERY
  • QUICK
R
  • RANGE (R)
  • RANK (R-Window)
  • RATE_LIMIT
  • READ (R)
  • REAL (R)
  • REBUILD
  • RECOVER
  • RECURSIVE (R)
  • REDUNDANT
  • REFERENCES (R)
  • REGEXP (R)
  • REGION
  • REGIONS
  • RELEASE (R)
  • RELOAD
  • REMOVE
  • RENAME (R)
  • REORGANIZE
  • REPAIR
  • REPEAT (R)
  • REPEATABLE
  • REPLACE (R)
  • REPLICA
  • REPLICAS
  • REPLICATION
  • REQUIRE (R)
  • REQUIRED
  • RESET
  • RESOURCE
  • RESPECT
  • RESTART
  • RESTORE
  • RESTORES
  • RESTRICT (R)
  • RESUME
  • REUSE
  • REVERSE
  • REVOKE (R)
  • RIGHT (R)
  • RLIKE (R)
  • ROLE
  • ROLLBACK
  • ROLLUP
  • ROUTINE
  • ROW (R)
  • ROW_COUNT
  • ROW_FORMAT
  • ROW_NUMBER (R-Window)
  • ROWS (R-Window)
  • RTREE
  • RUN
S
  • SAMPLERATE
  • SAMPLES
  • SAN
  • SAVEPOINT
  • SECOND
  • SECOND_MICROSECOND (R)
  • SECONDARY
  • SECONDARY_ENGINE
  • SECONDARY_LOAD
  • SECONDARY_UNLOAD
  • SECURITY
  • SELECT (R)
  • SEND_CREDENTIALS_TO_TIKV
  • SEPARATOR
  • SEQUENCE
  • SERIAL
  • SERIALIZABLE
  • SESSION
  • SESSION_STATES
  • SET (R)
  • SETVAL
  • SHARD_ROW_ID_BITS
  • SHARE
  • SHARED
  • SHOW (R)
  • SHUTDOWN
  • SIGNED
  • SIMPLE
  • SKIP
  • SKIP_SCHEMA_FILES
  • SLAVE
  • SLOW
  • SMALLINT (R)
  • SNAPSHOT
  • SOME
  • SOURCE
  • SPATIAL (R)
  • SPLIT
  • SQL (R)
  • SQL_BIG_RESULT (R)
  • SQL_BUFFER_RESULT
  • SQL_CACHE
  • SQL_CALC_FOUND_ROWS (R)
  • SQL_NO_CACHE
  • SQL_SMALL_RESULT (R)
  • SQL_TSI_DAY
  • SQL_TSI_HOUR
  • SQL_TSI_MINUTE
  • SQL_TSI_MONTH
  • SQL_TSI_QUARTER
  • SQL_TSI_SECOND
  • SQL_TSI_WEEK
  • SQL_TSI_YEAR
  • SQLEXCEPTION (R)
  • SQLSTATE (R)
  • SQLWARNING (R)
  • SSL (R)
  • START
  • STARTING (R)
  • STATISTICS
  • STATS
  • STATS_AUTO_RECALC
  • STATS_BUCKETS
  • STATS_COL_CHOICE
  • STATS_COL_LIST
  • STATS_EXTENDED (R)
  • STATS_HEALTHY
  • STATS_HISTOGRAMS
  • STATS_LOCKED
  • STATS_META
  • STATS_OPTIONS
  • STATS_PERSISTENT
  • STATS_SAMPLE_PAGES
  • STATS_SAMPLE_RATE
  • STATS_TOPN
  • STATUS
  • STORAGE
  • STORED (R)
  • STRAIGHT_JOIN (R)
  • STRICT_FORMAT
  • SUBJECT
  • SUBPARTITION
  • SUBPARTITIONS
  • SUPER
  • SWAPS
  • SWITCHES
  • SYSTEM
  • SYSTEM_TIME
T
  • TABLE (R)
  • TABLES
  • TABLESAMPLE (R)
  • TABLESPACE
  • TABLE_CHECKSUM
  • TELEMETRY
  • TELEMETRY_ID
  • TEMPORARY
  • TEMPTABLE
  • TERMINATED (R)
  • TEXT
  • THAN
  • THEN (R)
  • TIDB
  • TiDB_CURRENT_TSO (R)
  • TIFLASH
  • TIKV_IMPORTER
  • TIME
  • TIMESTAMP
  • TINYBLOB (R)
  • TINYINT (R)
  • TINYTEXT (R)
  • TO (R)
  • TOKEN_ISSUER
  • TOPN
  • TPCC
  • TPCH_10
  • TRACE
  • TRADITIONAL
  • TRAILING (R)
  • TRANSACTION
  • TRIGGER (R)
  • TRIGGERS
  • TRUE (R)
  • TRUNCATE
  • TSO
  • TTL
  • TTL_ENABLE
  • TTL_JOB_INTERVAL
  • TYPE
U
  • UNBOUNDED
  • UNCOMMITTED
  • UNDEFINED
  • UNICODE
  • UNION (R)
  • UNIQUE (R)
  • UNKNOWN
  • UNLOCK (R)
  • UNSET
  • UNSIGNED (R)
  • UNTIL (R)
  • UPDATE (R)
  • USAGE (R)
  • USE (R)
  • USER
  • USING (R)
  • UTC_DATE (R)
  • UTC_TIME (R)
  • UTC_TIMESTAMP (R)
V
  • VALIDATION
  • VALUE
  • VALUES (R)
  • VARBINARY (R)
  • VARCHAR (R)
  • VARCHARACTER (R)
  • VARIABLES
  • VARYING (R)
  • VIEW
  • VIRTUAL (R)
  • VISIBLE
W
  • WAIT
  • WARNINGS
  • WEEK
  • WEIGHT_STRING
  • WHEN (R)
  • WHERE (R)
  • WHILE (R)
  • WIDTH
  • WINDOW (R-Window)
  • WITH (R)
  • WITHOUT
  • WORKLOAD
  • WRITE (R)
X
  • X509
  • XOR (R)
Y
  • YEAR
  • YEAR_MONTH (R)
Z
  • ZEROFILL (R)