Type a tool name, for example "keyword density" or "transcript".
Format and beautify SQL queries instantly. Supports MySQL, PostgreSQL, SQLite, and ANSI SQL.
This free SQL formatter turns a cramped or messy query into clean, indented code you can read at a glance. Paste your SQL, choose 2 spaces, 4 spaces or tab, pick a keyword case, and click Format / Beautify. It works with MySQL, PostgreSQL, SQLite and ANSI SQL, and it needs no sign-in.
SQL formatting is the process of changing whitespace, line breaks and keyword casing so a query is easier to read without changing what it does. A database ignores extra spaces and newlines, so a query written on one line and the same query spread across ten lines return identical results.
A formatted query usually puts each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT) on its own line, indents joins and conditions beneath it, and writes keywords in one consistent case. Teams do this because readable SQL is faster to review, easier to debug and cleaner to track in version control.
Formatting is not optimizing. A formatter never rewrites a join, adds an index or changes a filter. If a query is slow, look at your database's query plan after you have formatted it, because a readable query makes the problem much easier to spot.
You can format a query in under ten seconds with four controls and one button. Follow these steps:
Here is a realistic query as it might come out of an application log, all on one line with no spaces after commas:
select u.id,u.name,u.email,o.total from users u left join orders o on u.id=o.user_id where u.active=1 and o.total>100 order by o.total desc limit 20;
With 2 Spaces and UPPERCASE selected, the keywords select, from, left join, on, where, and, order by and limit become uppercase. The major clauses start on their own lines, and the column list is split so each column can be scanned separately. The table names, aliases and column names keep exactly the spelling you typed.
The layout also reveals something the one-liner hid. The query uses a LEFT JOIN to keep users without orders, but the WHERE clause then filters on o.total. Users with no orders have a NULL total, so they are removed, and the LEFT JOIN behaves like an INNER JOIN. If you wanted those users, the condition belongs in the ON clause. Formatting did not fix the query, but it made the issue easy to see.
The two menus control how the final text looks and nothing else. Use this table to choose:
| Option | Choices | Best for |
|---|---|---|
| Indentation | 2 Spaces, 4 Spaces, Tab | Matching your team's code style |
| Keyword Case | UPPERCASE, lowercase | Enforcing one convention |
| Keyword Case | Preserve | Keeping the casing you typed |
Uppercase keywords are a widely used convention because they separate SQL words from table and column names, but no database requires them. Pick lowercase if your codebase uses it, or Preserve if you are formatting a snippet that must match existing code.
A good result has each major clause on its own line, joins and conditions indented under the clause they belong to, and subqueries indented one level deeper than the query around them. You should be able to find the WHERE clause without reading every word.
If the output is still mostly one long line, check for an unclosed quote. Single quotes, double quotes and backticks are treated as the start of a quoted value, so everything after a missing closing quote is left as-is. Add the missing quote and format again.
If a comment looks odd, remember that a line comment starting with two hyphens runs to the end of its line. When you use Minify on a query that contains line comments, check the output, because a comment that ends up sharing a line with code can hide the code after it. Remove or convert those comments to block comments first.
The quickest way to format SQL for any editor is to paste it here, format it and paste it back. That works the same for SQL Server Management Studio, Oracle SQL Developer, IntelliJ, VS Code and Notepad++.
Many editors have their own formatting command or extension, but each one can produce a slightly different layout. When you run every query through one formatter with the same indentation and keyword case, everyone on the team gets the same result. It is also handy when you are working on a machine where you cannot install an extension.
Use it whenever a query is hard to read or must look consistent. Typical situations include:
A few habits make the results more useful and avoid common surprises.
Front-end code needs the same care as queries. For HTML, CSS and JavaScript files, the code beautifier handles all three, and the rest of the web developer tools cover other everyday cleanup jobs.
This tool changes layout only. It does not run your query, connect to a database or check that table and column names exist. It also does not prove that your SQL is valid, so a query with a typo can still come out neatly indented.
Quoted text, quoted identifiers and PostgreSQL dollar-quoted bodies are kept exactly as you wrote them, so the contents of a function body between dollar signs are not reindented. Vendor-specific syntax, such as long procedural scripts, may be laid out less evenly than a standard SELECT. Skim the output before you commit it, and adjust a line by hand if a rare construct looks off.
When you want readable, consistently styled SQL without installing anything, paste your query into the formatter above, choose your indentation and keyword case, and click Format / Beautify. Then copy the result straight into your project.
Your report has been submitted. We will look into this issue.
A VPN changes your network exit. It does not guarantee anonymity.
Themes, plugins, code, video, audio, graphics & more from 90,000+ authors.
Web Development
Design & Media
Unlimited Access
Explore Envato Market