SQL Formatter & Beautifier

Paste a messy query and this SQL formatter turns it into clean, indented, readable code in one click.

50 free uses every 24 hoursUnlimited with Pro →

Private by design — your data stays on your deviceEverything runs right here in your browser. What you type is not sent to our server and is not stored.
  • Runs in your browser
  • Not stored
  • No sign-up

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?

  1. Paste your SQL into the input box.
  2. Choose the dialect that matches your database.
  3. Pick upper or lower keyword case and an indent size.
  4. Copy the formatted SQL.
How to use the SQL Formatter on OneHubTools: 4 steps with a real screenshot of the tool
How to use the SQL Formatter, step by step.

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.

Result from the SQL Formatter on OneHubTools
What the SQL Formatter gives you.

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

SettingOptionsTip
Keyword caseUPPER, lower, preserveUPPER keywords make clauses easy to scan
Indent size2 or 4 spacesMatch your team's code style
DialectMySQL, PostgreSQL, SQL Server, SQLite, Oracle and morePicks 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.

Limits and specs

PriceFree
Free use50 uses every 24 hours — shared with 178 other tools in the “Basic tools” group
Where it runsIn your browser
Sign-upNot needed
Muhammad Shahwaiz Gillani
Maintained and reviewed by Muhammad Shahwaiz GillaniSoftware engineer and founder of OneHubTools · Last reviewed

How we checked it: We tested it in Chrome with real code and data, including edge cases such as empty input and very long values.

Learn more

According to Wikipedia, SQL has been an ANSI and ISO standard for about 40 years and is used by almost every relational database, from small apps to systems with billions of rows.

Spotted a mistake or the tool did not work for you? Tell us and we will fix it.

Rate this tool

Ratings come only from signed-in users, so every rating is verified.

Only signed-in users can rate tools, so every rating shows a ✔ Verified badge.Sign in to rate

Frequently asked questions

Is this SQL formatter free?

Yes. It is free, needs no account and formats your SQL inside your browser.

Which databases are supported?

It supports eight dialects, including MySQL and PostgreSQL, SQL Server, SQLite and Oracle.

Will formatting change how my query runs?

No. Only spacing, line breaks and keyword case change. The query does exactly the same thing.

Can I choose upper or lower case keywords?

Yes. Choose the keyword case you prefer, such as SELECT or select.

Can it format stored procedures and long scripts?

Yes. Paste several statements at once and each one is formatted in turn. Very long scripts with unusual vendor syntax may need a small manual touch-up afterwards.

Is my SQL sent to a server?

No. Formatting happens on your device, so your queries stay private.