:: DEVELOPER ZONE
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 data type
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 Section 9.2, “Database, Table, Index, Column, and Alias Names”. The
server SQL mode is controlled as described in
Section 5.3.2, “The Server SQL Mode”.
A word that follows a period in a qualified name must be an identifier, so it is not necessary to quote it, even if it is a reserved word.
The words in the following table are explicitly reserved in MySQL.
Most of them are forbidden by standard SQL 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 if you quote it.
| ADD | ALL | ALTER |
| ANALYZE | AND | AS |
| ASC | ASENSITIVE | BEFORE |
| BETWEEN | BIGINT | BINARY |
| BLOB | BOTH | BY |
| CALL | CASCADE | CASE |
| CHANGE | CHAR | CHARACTER |
| CHECK | COLLATE | COLUMN |
| CONDITION | CONNECTION | CONSTRAINT |
| CONTINUE | CONVERT | CREATE |
| CROSS | CURRENT_DATE | CURRENT_TIME |
| CURRENT_TIMESTAMP | CURRENT_USER | 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 | DUAL |
| EACH | ELSE | ELSEIF |
| ENCLOSED | ESCAPED | EXISTS |
| EXIT | EXPLAIN | FALSE |
| FETCH | FLOAT | FOR |
| FORCE | FOREIGN | FROM |
| FULLTEXT | GOTO | GRANT |
| GROUP | HAVING | HIGH_PRIORITY |
| HOUR_MICROSECOND | HOUR_MINUTE | HOUR_SECOND |
| IF | IGNORE | IN |
| INDEX | INFILE | INNER |
| INOUT | INSENSITIVE | INSERT |
| INT | INTEGER | INTERVAL |
| INTO | IS | ITERATE |
| JOIN | KEY | KEYS |
| KILL | LABEL | LEADING |
| LEAVE | LEFT | LIKE |
| LIMIT | LINES | LOAD |
| LOCALTIME | LOCALTIMESTAMP | LOCK |
| LONG | LONGBLOB | LONGTEXT |
| LOOP | LOW_PRIORITY | MATCH |
| MEDIUMBLOB | MEDIUMINT | MEDIUMTEXT |
| MIDDLEINT | MINUTE_MICROSECOND | MINUTE_SECOND |
| MOD | MODIFIES | NATURAL |
| NOT | NO_WRITE_TO_BINLOG | NULL |
| NUMERIC | ON | OPTIMIZE |
| OPTION | OPTIONALLY | OR |
| ORDER | OUT | OUTER |
| OUTFILE | PRECISION | PRIMARY |
| PROCEDURE | PURGE | READ |
| READS | REAL | REFERENCES |
| REGEXP | RELEASE | RENAME |
| REPEAT | REPLACE | REQUIRE |
| RESTRICT | RETURN | REVOKE |
| RIGHT | RLIKE | SCHEMA |
| SCHEMAS | SECOND_MICROSECOND | SELECT |
| SENSITIVE | SEPARATOR | SET |
| SHOW | SMALLINT | SONAME |
| SPATIAL | SPECIFIC | SQL |
| SQLEXCEPTION | SQLSTATE | SQLWARNING |
| SQL_BIG_RESULT | SQL_CALC_FOUND_ROWS | SQL_SMALL_RESULT |
| SSL | STARTING | STRAIGHT_JOIN |
| TABLE | TERMINATED | THEN |
| TINYBLOB | TINYINT | TINYTEXT |
| TO | TRAILING | TRIGGER |
| TRUE | UNDO | UNION |
| UNIQUE | UNLOCK | UNSIGNED |
| UPDATE | USAGE | USE |
| USING | UTC_DATE | UTC_TIME |
| UTC_TIMESTAMP | VALUES | VARBINARY |
| VARCHAR | VARCHARACTER | VARYING |
| WHEN | WHERE | WHILE |
| WITH | WRITE | XOR |
| YEAR_MONTH | ZEROFILL |
MySQL allows some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list:
ACTION
BIT
DATE
ENUM
NO
TEXT
TIME
TIMESTAMP
© 1995-2005 MySQL AB. All rights reserved.

User Comments
Warning: query failed: Unknown column 'user.firstname' in 'field list' in /data0/sites/live/web-main/lib/mysql-cxn.php on line 69
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /data0/sites/live/web-main/lib/docbook.php on line 245
Add your own comment.