[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A common problem stems from trying to use an identifier such as a table or
column name that is the name of a built-in MySQL datatype or function,
such as TIMESTAMP
or GROUP
. You're allowed
to do this (for example, ABS
is allowed as a column name). However,
by default, no whitespace is allowed in function invocations between the
function name and the following `(' character. This requirement allows
a function call to be distinguished from a reference to a column name.
A side-effect of this behavior is that omitting a space in some contexts causes an identifier to be interpreted as a function name. For example, this statement is legal:
mysql> CREATE TABLE abs (val INT); |
But omitting the space after abs
causes a syntax error, because the
statement then appears to invoke the ABS()
function:
mysql> CREATE TABLE abs(val INT); |
If the server SQL mode includes the IGNORE_SPACE
mode value, the
server allows function invocations to have whitespace between a function
name and the following `(' character. This causes function names to be
treated as reserved words. As a result, identifiers that are the same as
function names must be quoted as described in 10.2 Database, Table, Index, Column, and Alias Names. The server
SQL mode is controlled as described in 1.8.2 Selecting SQL Modes.
The words in the following table are explicitly reserved in MySQL. Most of
them are forbidden by SQL-92 as column and/or table names (for example,
GROUP
). A few are reserved because MySQL needs them and (currently)
uses a yacc
parser. A reserved word can be used as an identifier by
quoting it.
Word | Word | Word |
ADD |
ALL
| ALTER
|
ANALYZE |
AND
| AS
|
ASC |
ASENSITIVE
| AUTO_INCREMENT
|
BDB |
BEFORE
| BERKELEYDB
|
BETWEEN |
BIGINT
| BINARY
|
BLOB |
BOTH
| BY
|
CALL |
CASCADE
| CASE
|
CHANGE |
CHAR
| CHARACTER
|
CHECK |
COLLATE
| COLUMN
|
COLUMNS |
CONDITION
| CONNECTION
|
CONSTRAINT |
CONTINUE
| CREATE
|
CROSS |
CURRENT_DATE
| CURRENT_TIME
|
CURRENT_TIMESTAMP |
CURSOR
| DATABASE
|
DATABASES |
DAY_HOUR
| DAY_MICROSECOND
|
DAY_MINUTE |
DAY_SECOND
| DEC
|
DECIMAL |
DECLARE
| DEFAULT
|
DELAYED |
DELETE
| DESC
|
DESCRIBE |
DETERMINISTIC
| DISTINCT
|
DISTINCTROW |
DIV
| DOUBLE
|
DROP |
ELSE
| ELSEIF
|
ENCLOSED |
ESCAPED
| EXISTS
|
EXIT |
EXPLAIN
| FALSE
|
FETCH |
FIELDS
| FLOAT
|
FOR |
FORCE
| FOREIGN
|
FOUND |
FRAC_SECOND
| FROM
|
FULLTEXT |
GRANT
| GROUP
|
HAVING |
HIGH_PRIORITY
| HOUR_MICROSECOND
|
HOUR_MINUTE |
HOUR_SECOND
| IF
|
IGNORE |
IN
| INDEX
|
INFILE |
INNER
| INNODB
|
INOUT |
INSENSITIVE
| INSERT
|
INT |
INTEGER
| INTERVAL
|
INTO |
IO_THREAD
| IS
|
ITERATE |
JOIN
| KEY
|
KEYS |
KILL
| LEADING
|
LEAVE |
LEFT
| LIKE
|
LIMIT |
LINES
| LOAD
|
LOCALTIME |
LOCALTIMESTAMP
| LOCK
|
LONG |
LONGBLOB
| LONGTEXT
|
LOOP |
LOW_PRIORITY
| MASTER_SERVER_ID
|
MATCH |
MEDIUMBLOB
| MEDIUMINT
|
MEDIUMTEXT |
MIDDLEINT
| MINUTE_MICROSECOND
|
MINUTE_SECOND |
MOD
| NATURAL
|
NOT |
NO_WRITE_TO_BINLOG
| NULL
|
NUMERIC |
ON
| OPTIMIZE
|
OPTION |
OPTIONALLY
| OR
|
ORDER |
OUT
| OUTER
|
OUTFILE |
PRECISION
| PRIMARY
|
PRIVILEGES |
PROCEDURE
| PURGE
|
READ |
REAL
| REFERENCES
|
REGEXP |
RENAME
| REPEAT
|
REPLACE |
REQUIRE
| RESTRICT
|
RETURN |
REVOKE
| RIGHT
|
RLIKE |
SECOND_MICROSECOND
| SELECT
|
SENSITIVE |
SEPARATOR
| SET
|
SHOW |
SMALLINT
| SOME
|
SONAME |
SPATIAL
| SPECIFIC
|
SQL |
SQLEXCEPTION
| SQLSTATE
|
SQLWARNING |
SQL_BIG_RESULT
| SQL_CALC_FOUND_ROWS
|
SQL_SMALL_RESULT |
SQL_TSI_DAY
| SQL_TSI_FRAC_SECOND
|
SQL_TSI_HOUR |
SQL_TSI_MINUTE
| SQL_TSI_MONTH
|
SQL_TSI_QUARTER |
SQL_TSI_SECOND
| SQL_TSI_WEEK
|
SQL_TSI_YEAR |
SSL
| STARTING
|
STRAIGHT_JOIN |
STRIPED
| TABLE
|
TABLES |
TERMINATED
| THEN
|
TIMESTAMPADD |
TIMESTAMPDIFF
| TINYBLOB
|
TINYINT |
TINYTEXT
| TO
|
TRAILING |
TRUE
| UNDO
|
UNION |
UNIQUE
| UNLOCK
|
UNSIGNED |
UPDATE
| USAGE
|
USE |
USER_RESOURCES
| USING
|
UTC_DATE |
UTC_TIME
| UTC_TIMESTAMP
|
VALUES |
VARBINARY
| VARCHAR
|
VARCHARACTER |
VARYING
| WHEN
|
WHERE |
WHILE
| WITH
|
WRITE |
XOR
| YEAR_MONTH
|
ZEROFILL |
The following symbols (from the table above) are disallowed by SQL-99 but allowed by MySQL as column/table names. This is because they are very natural names and a lot of people have already used them.
ACTION
BIT
DATE
ENUM
NO
TEXT
TIME
TIMESTAMP
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |