intro
Let's discover all the SQL reserved words in MySQL, PostgreSQL, SQL Server, and Oracle to become a master of SQL syntax.
Reserved words are building blocks that programming languages use to define their syntax and functionality. These words are predefined by the language and have specific meanings, such as controlling flow, declaring variables, or defining functions. SQL, too, has many reserved words. Time to explore all the SQL reserved words!
In this article, you will understand what reserved SQL words are, see those of all major databases, and learn how to deal with them when writing queries.
Let's dive right in!
Reserved Words in SQL: Definition
SQL reserved words, also known as SQL reserved identifiers, are predefined words that cannot be used as identifiers. These words are part of the SQL syntax and cannot be used in names of tables, columns, or other database objects—unless they are enclosed in special delimiters like double or single quotes or backticks, depending on the SQL dialect.
List of SQL Reserved Words
The SQL:2023 ISO/ANSI standard defines a list of reserved words in SQL. At the same time, each SQL dialect also has its own set of reserved SQL words.
Let's explore the list of SQL reserved words for:
Reserved Words in MySQL
Here is the list of reserved words in MySQL:
There is a total of 733 SQL reserved words in MySQL. See the updated list in the documentation.
Reserved Words in PostgreSQL
This is the list of PostgreSQL reserved keywords:
There are 96 SQL reserved words in PostgreSQL. Take a look at the updated list in the official documentation.
Reserved Words in SQL Server
Unfortunately, the SQL Server documentation does not provide a list of reserved words. It only includes a list of reserved SQL keywords, which are terms and expressions with some meaning in SQL Server.
Below is the list of reserved keywords in SQL Server:
There is a total of 187 reserved SQL keywords in SQL Server. Check out the documentation for more information.
Reserved Words in Oracle
This is the list of SQL reserved words in Oracle:
There are 109 reserved words in SQL within Oracle. Explore the documentation for the updated list.
Dealing With SQL Reserved Words
Reserved SQL words are predefined words that are reserved for specific purposes within the language. Usually, these words have a particular meaning in SQL statements and queries.
In particular, most SQL reserved words fall into one of these three categories:
In total, the SQL:2023 ANSI/ISO standard defines over 350 reserved words. Remembering them all is almost impossible, but using any of them in your query without the right precautions will result in an error. That can be a significant challenge!
Fortunately, dealing with reserved words in SQL becomes much easier with a tool like DbVisualizer. This comprehensive database client features a full-featured SQL editor with autocomplete capabilities:
Autocomplete helps you type SQL statements faster and more accurately by suggesting keywords, table names, column names, and functions as you type. This feature significantly aids in SQL development. On top of that, DbVisualizer offers syntax error highlighting, making it easier to detect errors in your SQL queries:
Conclusion
In this guide, you explored the list of reserved SQL words in MySQL, PostgreSQL, SQL Server, and Oracle. You also learned how to use them in SQL queries. With hundreds of reserved words in SQL, remembering them all can be challenging. This is where a powerful database client like DbVisualizer comes in!
With its advanced autocomplete capabilities, DbVisualizer simplifies writing queries across more than 50 databases. Additionally, this powerful tool offers advanced query optimization, query formatting, and the ability to generate ERD-type schemas with a single click. Try DbVisualizer for free!
FAQ
What happens when trying to use a reserved word in SQL?
Using reserved words in SQL without proper handling, such as by wrapping them with single or double quotes or backticks like ”`” can lead to syntax errors. In some cases, inserting these words in specific parts of a query can even lead to unexpected behavior.
How many SQL reserved words are there?
The SQL:2023 ISO standard defines more than 350 reserved words, but each specific dialect has its own set of reserved SQL words. Follow the links below for more details:
What is the difference between a reserved keyword and a non-reserved keyword in SQL?
SQL distinguishes between reserved and non-reserved keywords. Reserved keywords are the only real keywords, and they are never allowed as identifiers. Non-reserved keywords only have a special meaning in particular contexts and can be used as identifiers in other contexts. The concept of non-reserved keywords essentially only exists to declare that a specific word has some predefined meaning in some contexts.
How to use reserved SQL words in a query?
To use reserved SQL words as identifiers in a query, you typically need to enclose them in double quotes, single quotes, or backticks, based on the SQL dialect you are using.
Where can I find a list of list of SQL reserved words?
You can find a list of all reserved SQL words in all major database systems in this article and on the Wikipedia "List of SQL reserved words" page.