Skip to content
codinganthem
All tools/Formatters/SQL Formatter

SQL Formatter

Format and beautify SQL queries online with dialect-aware indentation, for free. Supports MySQL, PostgreSQL, SQLite, and more — no sign-up.

More
Buy me a coffee

How to format SQL

Paste a query, pick the dialect that matches your database, and the formatter puts each clause on its own line, indents subqueries and uppercases keywords. Formatting only changes whitespace and keyword case, never what the query does, so it's safe to run on queries you're about to execute.

Before and after

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)>5 order by orders desc

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) > 5
ORDER BY
  orders DESC

Why the dialect matters

Databases differ in quoting and syntax: MySQL quotes names with backticks, PostgreSQL and standard SQL use double quotes, and features like :: casts or RETURNING exist only in some dialects. Choosing the right dialect lets the formatter recognise these instead of splitting them in odd places.

Conventions that make queries easier to review

  • One selected column per line, so a diff shows exactly which column changed.
  • Each JOIN on its own line with its ON condition, so missing join conditions stand out.
  • Use CTEs (WITH name AS (...)) instead of deeply nested subqueries for multi-step logic.
  • Name every aggregate with AS, and prefer explicit column lists over SELECT * in application code.

Related tools

To turn a list of values into an IN (...) clause, use the SQL IN Generator. To write a query from a plain-English description, try the AI Text-to-SQL Generator, and check its output before running it.

Frequently asked questions

Does formatting change what my SQL does?+

No. It only changes whitespace and keyword case. The query runs the same way.

Which SQL dialects are supported?+

Standard SQL, MySQL, PostgreSQL, SQLite and several others. Pick the one that matches your database so dialect-specific syntax is recognised.

Is my query sent to a server?+

No. Formatting runs in your browser, so queries with real table names or data stay on your machine.

Should SQL keywords be uppercase?+

It's a convention, not a rule: SQL keywords are case-insensitive. Uppercase keywords make it easier to tell them apart from table and column names.