MySQL Reserved Words

The database language MySQL has a number of reserved words that should not be used in queries or for field names. Some of the big ones are:

  • Add
  • All
  • Between
  • Both
  • Check
  • Current_Date
  • Drop
  • For
  • From
  • Group
  • INT
  • Key
  • Load
  • Lock
  • Null
  • On
  • Out
  • Real
  • Repeat
  • Table
  • Use
  • Write

And so it goes. I came across the official list when I couldn't work out why this query wouldn't work:

SQL:
  1. SELECT COUNT(id) FROM messages WHERE READ = ‘0AND TO = $logged_in_id

The reason? Both "to" and "read" are reserved words and the query failed. See the full list here:

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Posted on 25 June '07 by Steve, under PHP.

One Response to “MySQL Reserved Words”

  1. Bassel Safadi says:

    it's very impotent to be aware of the reserved words, I built a cms that has a filed in each table called (CONDITION) and now its reserved in mysql 5..

    :( it took me a lot of time to alter all the tables and the php code in all the sites that uses this cms :(

    Thanks Steve

Leave a Reply