SQL Formatter
Guide: How to Format SQL So Anyone Can Read It
Nothing you enter or choose here leaves your device. This tool runs in your browser.
Before and after
A query pasted from a log or a chat message usually arrives as one long line. Here's one, and what the formatter makes of it:
select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id,u.name having count(o.id)>2 order by orders desc limit 10;
SELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 GROUP BY u.id, u.name HAVING COUNT(o.id) > 2 ORDER BY orders DESC LIMIT 10;
Only spacing, line breaks and the case of keywords changed. Table and column names, and anything inside quotes, are left exactly as written, so the query does the same thing as before.
Pick the right dialect
SQL isn't one language. Each database has its own quirks, and the formatter needs to know which one so it doesn't split or mangle them. The choice matters for things like:
| Detail | MySQL | PostgreSQL | SQL Server |
|---|---|---|---|
| Quoting names | Backticks | Double quotes | Square brackets |
| Limiting rows | LIMIT 10 | LIMIT 10 | TOP 10 |
| String joining | CONCAT() | Two vertical bars | Plus sign |
| Variables | At sign | Dollar quoting in functions | At sign, DECLARE |
Standard SQL, MariaDB, Oracle, SQLite, BigQuery, Snowflake and Redshift are available too. If the output looks odd, the first thing to try is another dialect.
Habits that make queries readable
- Put each selected column on its own line, so a diff shows exactly which column was added.
- Keep keywords in capitals and names in lower case. The eye finds the structure first.
- Give every table a short alias and use it on every column, so it's clear where each one comes from.
- Indent joins under the table they extend, and put the join condition on the same line.
- Add a comment above any condition whose reason isn't obvious.
What Minify is for
Minify does the opposite: it removes comments and extra whitespace and puts the query on one line, leaving text inside quotes untouched. That's handy for putting SQL in a log line, a config file or a string in code, where line breaks cause trouble. Be careful that a comment which uses two dashes runs to the end of its line, so the tool removes it rather than letting it swallow the rest of a flattened query.
Spotting mistakes by formatting
Formatting is a quick way to catch errors. A missing comma shows up when two column names end up on one line. A missing closing bracket makes the rest of the query indent wrongly. A join without a condition looks conspicuous on its own line. Format first, then read.
Your SQL stays in the browser, so queries that mention private tables are safe to paste. If a query result comes back as JSON, tidy that with the JSON formatter, and use the string escape tool when you need to put SQL inside a string in your code.
Written by Akinrinmade Michael · Updated October 24, 2026
How to use
- 1Paste your SQL query into the input box.
- 2Choose your database dialect, indentation and keyword case.
- 3Read the formatted query on the right.
- 4Click Copy SQL, or switch to Minify for a single compact line.
Frequently asked questions
Which databases are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle (PL/SQL), SQLite, BigQuery, Snowflake and Redshift. Pick the dialect that matches your database so dialect-specific syntax is understood.
Will formatting change what my query does?
No. Only whitespace, line breaks and the letter case of keywords change. Table names, column names and quoted text are left exactly as you wrote them.
What does Minify do?
It removes comments and extra whitespace and puts the query on one line, while leaving the text inside quotes untouched. It is handy for logs, config files and embedding SQL in code.
Is my SQL sent anywhere?
No. Formatting runs in your browser, so queries that mention private tables or data stay on your device.
Read the guide
Learn how this works and how to get the most from it.
Developer
How to Format SQL So Anyone Can Read It
Simple formatting habits that make SQL queries easy to read and review, plus how to handle quotes and when a formatter helps.
3 min read
Related tools
JSON Formatter & Validator
Prettify, minify and validate JSON, with error line numbers.
Regex Tester
Test regular expressions live, with match highlighting and groups.
Text Diff Checker
Compare two texts side by side and see exactly what changed.
Mock Data Generator
Generate fake names, emails, dates and more as JSON, CSV or SQL.