This SQL formatter turns long, one-line queries into neat code with clear indentation and line breaks. Choose your database dialect, pick the keyword case and indent size, and copy the result. It works as an SQL beautifier for MySQL and PostgreSQL, SQL Server, SQLite, Oracle and other common dialects, eight in total.
How do I format an SQL query?
- Paste your SQL into the input box.
- Choose the dialect that matches your database.
- Pick upper or lower keyword case and an indent size.
- Copy the formatted SQL.

The query never leaves your browser, so it is safe to format SQL query text that includes table names from a private project.
Before and after
A query copied from a log often looks like this:
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 order by orders desc
After formatting, each clause starts on its own line: SELECT with the column list indented below it, then FROM, LEFT JOIN, WHERE, GROUP BY and ORDER BY. You can see the logic at a glance and spot a missing join condition much faster.

Why formatting matters
- Reviews are quicker. Teammates can read a formatted query without scrolling sideways.
- Bugs stand out. A wrong JOIN or a missing WHERE is easier to spot when every clause has its own line.
- Diffs are cleaner. In Git, a change to one column shows up as one changed line.
- Learning is easier. Students can see how a query is built from its parts.
Keyword case and indent size
| Setting | Options | Tip |
|---|---|---|
| Keyword case | UPPER, lower, preserve | UPPER keywords make clauses easy to scan |
| Indent size | 2 or 4 spaces | Match your team's code style |
| Dialect | MySQL, PostgreSQL, SQL Server, SQLite, Oracle and more | Picks the right functions and quoting rules |
Most style guides use upper-case keywords and lower-case table and column names. Whatever you choose, stay consistent across a project.
Does the SQL formatter change my query?
No. It only changes spaces, line breaks and keyword case. It does not reorder columns, rename tables or change values. The formatted query runs exactly like the original. If the input has a syntax error, the result may look odd at that point, which is a useful hint about where the mistake is.
Tips for readable SQL
Give tables short, meaningful aliases such as u for users and o for orders. Put each selected column on its own line when there are more than three. Use comments to explain unusual filters. Avoid SELECT * in production code, so the query keeps working when a new column is added.
Related developer tools
For JSON from an API, use the JSON formatter. For HTML, CSS or JavaScript, the code beautifier does the same job, and the code minifier does the opposite. To test a pattern inside a WHERE clause, try the regex tester. Turn a column of IDs into an IN list with text to comma list.
