SQL Formatter

Format and beautify SQL queries for various dialects.

Input SQL

Formatted SQL

SELECT
  *
FROM
  users
WHERE
  id = 1

About SQL formatting

SQL becomes unreadable surprisingly quickly. A single query that started as SELECT id FROM users can grow into a hundred-line CTE with three nested joins, a window function, and a subquery used as a derived table. A formatter restores sanity by splitting clauses onto their own lines, aligning column lists, and indenting join conditions consistently. The point is not pretty output for its own sake — it is making bugs visible during code review.

This formatter understands the dialects of PostgreSQL, MySQL, SQLite, MS SQL Server, BigQuery, and Snowflake. Pick the dialect that matches your database to get the right keyword set and reserved-word handling. As with everything else on the site, the query runs through a parser inside your browser — your SQL is never sent to a server.

How to use

  1. Paste your SQL query into the input.
  2. Pick the dialect (Postgres, MySQL, SQLite, MS SQL, BigQuery, Snowflake).
  3. Choose an indentation style — uppercase keywords with two-space indent is the default.
  4. Copy the formatted output back into your editor.

Common use cases

  • Cleaning up auto-generated ORM SQL before posting it to a code review.
  • Reformatting a one-line query lifted from a log file.
  • Producing consistently-styled migrations across a codebase.
  • Teaching SQL to juniors with readable, hand-styled examples.

Frequently asked questions

Does the formatter execute my query?

No. It only parses and reformats. Nothing is connected to a database.

Why is keyword case mismatched in the output?

The formatter normalises keywords to UPPERCASE by default. You can switch to lowercase or "preserve as written" in the settings.

Can it handle multi-statement scripts?

Yes. Statements separated by ";" are formatted individually with a blank line between them.

Advertisement