Developer Tools

SQL Formatter

Turn a long, tangled query into clearly structured SQL, with each clause on its own line and keywords in the case you prefer. Pick your database dialect for accurate results.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use SQL Formatter

  1. Paste one or more SQL statements into the input editor.
  2. Select your database dialect so that its specific syntax is recognised.
  3. Choose the keyword case and indentation.
  4. Select Format SQL, then copy the result.

SQL Formatter features

Dialect aware

Understands the syntax of MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake and others.

Clause-per-line layout

SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY each start a new line with their contents indented.

Keyword casing

Convert keywords to upper case, lower case or leave them as typed.

Handles complex queries

Subqueries, CTEs, window functions and CASE expressions are nested and indented.

Comments and strings preserved

Text inside quotes and comments is never altered.

Queries stay private

Nothing is uploaded; formatting is done in your browser.

When to use SQL Formatter

  • Making a query generated by an ORM or logged by an application readable.
  • Cleaning up SQL before a code review or before saving it to version control.
  • Understanding a long report query written by someone else.
  • Preparing SQL for documentation or a support ticket.

SQL Formatter FAQ

Does formatting change what the query does?

No. Only whitespace and, if you choose, the case of keywords is changed. Identifiers, string literals and the order of operations are untouched.

Why choose a dialect?

Dialects differ in quoting, operators and keywords: backticks in MySQL, square brackets in SQL Server, :: casts and dollar quoting in PostgreSQL. Selecting the right one prevents those constructs being misread.

Does it check that my SQL is valid?

Not fully. It reports text it cannot tokenise, but it does not know your schema and does not verify that the query would run. Use your database's own parser for that.

Should SQL keywords be upper case?

It is a convention, not a requirement. Upper-case keywords make the structure of a query stand out from table and column names, which is why many style guides prefer them.

Can it format stored procedures?

Procedural code is formatted on a best-effort basis. Standard statements inside it are handled well; vendor-specific control flow may be laid out less neatly.

A readable SQL style

SQL is declarative: a statement describes the result wanted, clause by clause. Laying those clauses out vertically, with the selected columns, joined tables and filter conditions each indented beneath their keyword, lets a reader take in the shape of a query before reading the details. It also makes diffs meaningful, because adding a column or a condition changes one line instead of rewrapping a paragraph.

Consistent formatting matters most for long analytical queries with several joins and subqueries, where it is easy to lose track of which condition belongs to which join. Running such a query through a formatter is often the fastest way to spot a misplaced parenthesis or a join without a condition.

Other useful tools