Treatment of Reserved Words in MySQL

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 the section called “Database, Table, Index, Column, and Alias Names”. The server SQL mode is controlled as described in the section called “The Server SQL Mode”.

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.

WordWordWord
ADDALLALTER
ANALYZEANDAS
ASCASENSITIVEBEFORE
BETWEENBIGINTBINARY
BLOBBOTHBY
CALLCASCADECASE
CHANGECHARCHARACTER
CHECKCOLLATECOLUMN
COLUMNSCONDITIONCONNECTION
CONSTRAINTCONTINUECONVERT
CREATECROSSCURRENT_DATE
CURRENT_TIMECURRENT_TIMESTAMPCURRENT_USER
CURSORDATABASEDATABASES
DAY_HOURDAY_MICROSECONDDAY_MINUTE
DAY_SECONDDECDECIMAL
DECLAREDEFAULTDELAYED
DELETEDESCDESCRIBE
DETERMINISTICDISTINCTDISTINCTROW
DIVDOUBLEDROP
DUALEACHELSE
ELSEIFENCLOSEDESCAPED
EXISTSEXITEXPLAIN
FALSEFETCHFIELDS
FLOATFORFORCE
FOREIGNFOUNDFROM
FULLTEXTGOTOGRANT
GROUPHAVINGHIGH_PRIORITY
HOUR_MICROSECONDHOUR_MINUTEHOUR_SECOND
IFIGNOREIN
INDEXINFILEINNER
INOUTINSENSITIVEINSERT
INTINTEGERINTERVAL
INTOISITERATE
JOINKEYKEYS
KILLLEADINGLEAVE
LEFTLIKELIMIT
LINESLOADLOCALTIME
LOCALTIMESTAMPLOCKLONG
LONGBLOBLONGTEXTLOOP
LOW_PRIORITYMATCHMEDIUMBLOB
MEDIUMINTMEDIUMTEXTMIDDLEINT
MINUTE_MICROSECONDMINUTE_SECONDMOD
MODIFIESNATURALNOT
NO_WRITE_TO_BINLOGNULLNUMERIC
ONOPTIMIZEOPTION
OPTIONALLYORORDER
OUTOUTEROUTFILE
PRECISIONPRIMARYPRIVILEGES
PROCEDUREPURGEREAD
READSREALREFERENCES
REGEXPRENAMEREPEAT
REPLACEREQUIRERESTRICT
RETURNREVOKERIGHT
RLIKESCHEMASCHEMAS
SECOND_MICROSECONDSELECTSENSITIVE
SEPARATORSETSHOW
SMALLINTSONAMESPATIAL
SPECIFICSQLSQLEXCEPTION
SQLSTATESQLWARNINGSQL_BIG_RESULT
SQL_CALC_FOUND_ROWSSQL_SMALL_RESULTSSL
STARTINGSTRAIGHT_JOINTABLE
TABLESTERMINATEDTHEN
TINYBLOBTINYINTTINYTEXT
TOTRAILINGTRIGGER
TRUEUNDOUNION
UNIQUEUNLOCKUNSIGNED
UPDATEUSAGEUSE
USINGUTC_DATEUTC_TIME
UTC_TIMESTAMPVALUESVARBINARY
VARCHARVARCHARACTERVARYING
WHENWHEREWHILE
WITHWRITEXOR
YEAR_MONTHZEROFILL 

MySQL allows some keywords to be used as unquoted identifiers because many people have already used them. Examples are those in the following list: