Search the MySQL manual:

6.1.7 Is MySQL Picky About Reserved Words?

A common problem stems from trying to create a table with column names that use the names of datatypes or functions built into MySQL, such as TIMESTAMP or GROUP. You're allowed to do it (for example, ABS is allowed as a column name). However, by default, in function invocations no whitespace is allowed between the function name and the following `(' character, so that a function call can be distinguished from a reference to a column name.

If you start the server with the --ansi or --sql-mode=IGNORE_SPACE option, 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, column names that are the same as function names must be quoted as described in section 6.1.2 Database, Table, Index, Column, and Alias Names.

The following words 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 is (currently) using a yacc parser:

Word Word Word
ADD ALL ALTER
ANALYZE AND AS
ASC ASENSITIVE AUTO_INCREMENT
BDB BEFORE BERKELEYDB
BETWEEN BIGINT BINARY
BLOB BOTH BTREE
BY CALL CASCADE
CASE CHANGE CHAR
CHARACTER CHECK COLLATE
COLUMN COLUMNS CONNECTION
CONSTRAINT CREATE CROSS
CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP
CURSOR DATABASE DATABASES
DAY_HOUR DAY_MINUTE DAY_SECOND
DEC DECIMAL DECLARE
DEFAULT DELAYED DELETE
DESC DESCRIBE DISTINCT
DISTINCTROW DIV DOUBLE
DROP ELSE ELSEIF
ENCLOSED ERRORS ESCAPED
EXISTS EXPLAIN FALSE
FIELDS FLOAT FOR
FORCE FOREIGN FROM
FULLTEXT GRANT GROUP
HASH HAVING HIGH_PRIORITY
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_SECOND
MOD MRG_MYISAM 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 RETURNS REVOKE
RIGHT RLIKE RTREE
SELECT SENSITIVE SEPARATOR
SET SHOW SMALLINT
SOME SONAME SPATIAL
SPECIFIC SQL_BIG_RESULT SQL_CALC_FOUND_ROWS
SQL_SMALL_RESULT SSL STARTING
STRAIGHT_JOIN STRIPED TABLE
TABLES TERMINATED THEN
TINYBLOB TINYINT TINYTEXT
TO TRAILING TRUE
TYPES UNION UNIQUE
UNLOCK UNSIGNED UNTIL
UPDATE USAGE USE
USER_RESOURCES USING VALUES
VARBINARY VARCHAR VARCHARACTER
VARYING WARNINGS 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 some of these names are very natural names and a lot of people have already used them.

User Comments

Posted by Martin Francis on Monday February 10 2003, @7:54am[Delete] [Edit]

The way around this is to place backticks (`name`) around the table name and relevant column names, for example:

CREATE TABLE `group` (
ID CHAR(13) NOT NULL,
createdByID CHAR(13) NOT NULL,
`read` CHAR(1) NULL,
PRIMARY KEY (ID)
)

As a rule, I use backticks on all table names and all column references anyway to avoid any suprises.

Posted by grungyimp on Wednesday February 12 2003, @3:25pm[Delete] [Edit]

The better way around it is to stick with the ANSI standard double-quotes, not backticks.

Also, if you have a double-quote in the variable name, you just use two double-quotes, e.g. Annoying "variable name" becomes "Annoying ""variable name""".

Posted by Brian Fearon on Friday April 4 2003, @5:09am[Delete] [Edit]

Backticks are the MySQL style of quoting table and column names. Only if you are running in ANSI mode should you use double-quotes.

Posted by [name withheld] on Monday July 14 2003, @10:47am[Delete] [Edit]

The underscore ("_") is a 'reserved character' since there is support for using it as a wildcard charcter for database names. Here is an example:

mysql> SHOW DATABASES LIKE 'm_sql'\G
*************************** 1. row ***************************
Database (m_sql): mysql
1 row in set (0.00 sec)

Wildcard characters are discussed here:
http://www.mysql.com/doc/en/String_comparison_functions.html

Add your own comment.