Skip to content
Tutorials Center
My learning

Topics

SQL Reference ยท Dialects and Concepts

SQL reserved keywords

What reserved and non-reserved keywords are in SQL, the words that most often collide with column and table names, and how SQLite, MySQL and others differ.

A keyword is a word that has a meaning in the SQL grammar, such as SELECT, FROM or WHERE. A reserved keyword may not be used as a plain identifier (a table, column or alias name) without quoting. A non-reserved keyword has a special meaning only in certain positions and is usable as a name elsewhere.

Each database has its own list, and the lists change between versions. The standard also keeps a list of words reserved for future use. The practical rule is short: do not name your own tables and columns with keywords, and you will never need to look up whether a word is reserved.

Try it

SQL A reserved word as a column name (fails on purpose) ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

SQL The same table with a quoted name, and a safe rename ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

Words that often collide with names

These are the words that most often cause trouble because they are natural column or table names. Whether each is reserved depends on the product, so the safe habit is to avoid them all or to pick a more specific name.

Word Typical trouble Better name
order, group Reserved in every major dialect purchase_order, team_group
user Reserved in PostgreSQL, Oracle and SQL Server; a function in some app_user, account
table, index, view Reserved in most dialects data_table, index_name
key, value key is reserved in MySQL and SQL Server; value is a keyword in some setting_key, setting_value
date, time, timestamp Type names; reserved in Oracle order_date, created_at
limit, offset Reserved in MySQL, PostgreSQL, SQLite max_rows, skip_count
rank, row, rows, groups, window Reserved in newer versions (MySQL 8 added many window-function words) position, grade
desc, asc Reserved everywhere (sort direction) description
check, default, references, primary, unique, constraint Reserved: constraint syntax name by content
case, when, then, else, end Reserved: CASE syntax case_number
to, by, in, is, as, on, or, and, not, null Reserved everywhere

The statement keywords themselves are always reserved: SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, JOIN, UNION, HAVING, VALUES, SET, INTO, DISTINCT, LIKE, BETWEEN, EXISTS, CAST, CURRENT_DATE, CURRENT_TIMESTAMP.

Dialect differences

Topic SQLite PostgreSQL MySQL SQL Server Oracle
How strict Lenient: many keywords can be names where unambiguous Moderate, documented per word as reserved or non-reserved Strict; the list grows with versions Strict, and some words reserved for ODBC Strict, with a separate V$RESERVED_WORDS view
Quote an identifier "x" "x" `x` [x] "x"
Find the list Keyword list in the docs; sqlite3_keyword_name() in C Appendix "SQL Key Words"; pg_get_keywords() INFORMATION_SCHEMA.KEYWORDS (8.0+) Documentation lists reserved words SELECT * FROM v$reserved_words
SQL
-- PostgreSQL: ask the server
SELECT word, catdesc FROM pg_get_keywords() WHERE word = 'user';

-- MySQL 8
SELECT word, reserved FROM information_schema.keywords WHERE word = 'rank';

-- Oracle
SELECT keyword, reserved FROM v$reserved_words WHERE keyword = 'DATE';

Because lists differ, a schema that works on one engine can break on another. The only reliable portable approach is to avoid keywords in names.

Usage notes

  • Check new versions. Upgrading a database can reserve a word you already use as a column name. MySQL 8 reserved rank, groups and window, which broke many older schemas.
  • Quoting fixes it, but then you must quote forever. Every query, view and ORM mapping that touches the name needs the same quotes. See identifier quoting.
  • SQLite sometimes forgives. It lets some keywords through as names where the meaning is clear, so a schema may work in SQLite and fail in PostgreSQL or MySQL.
  • Case does not matter for keywords. select, Select and SELECT are identical; uppercase keywords are a style choice that makes queries easier to scan.
  • Function names are different. Words like COUNT, LENGTH or ROUND are generally not reserved, but giving a column the name of a function can confuse readers.
  • Do not use CURRENT_* words, NULL, TRUE and FALSE as names; they are values.