About the SQL Formatter
SQL Formatter takes a query written on one long line, or laid out in a hurry, and prints it with each clause on its own line and a consistent indent. Pick the dialect that matches your database, choose UPPER, lower or unchanged keywords, set the indent to two spaces, four spaces or a tab, and paste your SQL. A Minify button does the opposite and squashes the query onto one line. The tool changes layout and keyword case only. It never runs your query or checks it against a database, so a neatly formatted query can still be wrong. Formatting is done in your browser and nothing is sent anywhere.
Updated October 2026
How to use the SQL Formatter
- 1Choose the SQL dialect that matches your database.
- 2Set the keyword case, indent and the number of blank lines between queries.
- 3Paste your SQL, or press Try a sample. The formatted query appears on the right.
- 4Copy the result or download formatted.sql. Press Minify for a one-line version.
Why format SQL
Queries copied from logs, ORMs or old scripts are often a single unreadable line. When every clause has its own line, you can see at a glance which columns are selected, which tables are joined and which filters apply. That makes reviews quicker and mistakes easier to spot, and it keeps version-control changes small because only the lines that really changed show up.
Formatting does not check your SQL against a database. It rearranges the text, so a query can look tidy and still be wrong.
Choosing a dialect
SQL is a family of languages. Quoting rules, functions and extra keywords differ between databases. Choosing the dialect lets the formatter recognise vendor features such as backtick-quoted names in MySQL, square-bracket names in SQL Server or double-colon casts in PostgreSQL. If you are unsure, start with Standard SQL. If a query is rejected, try the dialect of the database it came from.
Keyword case and indentation
- UPPER makes SELECT, FROM and WHERE stand out from table and column names. It is the most common convention.
- lower suits teams whose style guide prefers lowercase.
- Keep leaves every keyword as it was typed.
- 2 spaces keeps deeply nested queries narrow, 4 spaces is roomier, and a tab lets each reader choose the width.
- Lines between queries controls the gap when you paste several statements separated by semicolons.
Minifying queries
Minify collapses runs of spaces and line breaks into single spaces and removes -- and /* */ comments. Text inside single quotes, double quotes, backticks and square brackets is kept exactly, so a string such as 'a b' is not altered. One-line SQL is handy for pasting into a command line, a config file or a log search.
Because comments are removed, use the formatted version if a comment carries meaning, such as an optimiser hint. For other code, see Code Minifier, and for data files try JSON Formatter or XML Formatter. If the data is JSON rather than a query, use the JSON Formatter, and compare two versions of a query with the Diff Checker.
Features
- Eight dialects including MySQL, PostgreSQL, SQLite and SQL Server
- Keywords in upper case, lower case or as typed
- Indent with 2 spaces, 4 spaces or a tab
- Minify to a single line
- Counts the statements in your text
- Plain-language error when the query can't be formatted
Frequently asked questions
How do I format a SQL query?
Paste it into the left box. The formatted version appears on the right, with SELECT, FROM, WHERE and the other clauses each starting a new line and their contents indented beneath. Copy it or download formatted.sql.
Does it change what my query does?
It only changes whitespace and, if you choose, the case of keywords. Names of tables and columns keep their case. The query is not run, so formatting can not fix a wrong query, and it can not find a mistake in the logic.
Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), BigQuery and Oracle PL/SQL. Pick the closest match. Very unusual vendor syntax may be rejected or laid out oddly.
How do I make SQL keywords uppercase?
Leave Keyword case on UPPER, which is the default. Choose lower to make them lowercase, or Keep to leave each keyword exactly as you typed it.
Can I minify SQL?
Yes. Press Minify and the query becomes a single line with extra spaces removed. Text inside quotes is kept exactly as written. Comments are removed, which matters if your database reads hints such as /*+ ... */ from them.
Is my query sent anywhere?
No. The formatter runs in the page on your own device. Nothing you paste leaves the browser, which is helpful when queries mention real table names.
Why do I get a “Couldn't format this SQL” message?
The formatter reads your text as a list of tokens and stops when it finds something it can't understand, such as an unclosed bracket. The message quotes the first line of the problem. Fix that spot, or try another dialect.