1. Home
  2. Coding Tools
  3. SQL Formatter

SQL Formatter

Format messy SQL into clean, readable queries with proper indentation and uppercase keywords. Supports MySQL, PostgreSQL, SQL Server, SQLite, Oracle and more.

Runs locally in your browser. Your files and data are never uploaded or stored.

About the SQL Formatter

Long SQL queries written on one line, generated by ORMs or copied from logs are hard to read and debug. The SQL Formatter restructures them with each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) on its own line, indented columns and conditions, and consistently cased keywords.

It supports the syntax of popular databases, including MySQL, PostgreSQL, SQL Server (T-SQL), SQLite, Oracle PL/SQL, MariaDB and BigQuery, powered by the open-source sql-formatter library running in your browser. Your queries, which may contain table names or data, are never sent anywhere.

Before and after: a formatted SQL query

A query copied from an application log:

select o.id,c.name,sum(i.qty*i.price) total from orders o join customers c on c.id=o.customer_id join items i on i.order_id=o.id where o.status='paid' group by o.id,c.name order by total desc

After formatting with uppercase keywords:

SELECT
  o.id,
  c.name,
  sum(i.qty * i.price) total
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
  JOIN items i ON i.order_id = o.id
WHERE
  o.status = 'paid'
GROUP BY
  o.id,
  c.name
ORDER BY
  total DESC

Why this helps

  • You can see every join and its condition, which is where most wrong results come from.
  • A missing column in GROUP BY or a filter in the wrong place is much easier to spot.
  • Formatted queries are easier to review in team chats and pull requests.

Tip: choose the dialect that matches your database. Functions and quoting rules differ between MySQL, PostgreSQL and SQL Server, and the right dialect keeps them intact.

How to use the SQL Formatter

  1. Paste your SQL query.
  2. Choose your database dialect and keyword case.
  3. Review the formatted SQL.
  4. Copy it or download it as a .sql file.

Frequently asked questions

Does it check if my SQL is correct?

It parses the query to format it and reports syntax it cannot understand, but it does not run the query or check table names.

Can it format multiple statements?

Yes. Separate statements with semicolons and they will all be formatted.