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]SELECT COUNT(id) FROM messages WHERE read = ‘0′ AND to = $logged_in_id[/SQL]

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

One Reply to “MySQL Reserved Words”

  1. 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

Your email address will not be published. Required fields are marked *