SQL formatter

Paste a query and get it laid out with each clause on its own line and consistent indentation. Choose your database dialect, the case of keywords and the indentation.

  • Free
  • No sign-up
  • Runs in your browser
sql-formatter

100% private — your text is processed in your browser and never sent to any server.

How it works

Paste your query

A single statement or several, from a log, an ORM or an editor.

Choose dialect and style

Database dialect, keyword case and indentation.

Copy the formatted SQL

Use it in code review, documentation or your editor.

Queries you can read again

SQL grows into unreadable lines quickly: a query printed by an ORM, copied from a log, written by a colleague in a hurry or squeezed by a tool into a single line. Reading it, reviewing it or debugging it is much easier when every clause has its own line, joins and conditions are indented, and keywords stand out. This formatter reorganises the layout of a query without changing what it does.

What the formatting does

  • Puts SELECT, FROM, WHERE, GROUP BY, ORDER BY and the other major clauses on separate lines.
  • Lists selected columns one per line, and indents joins, conditions, subqueries and CASE expressions so the nesting is visible.
  • Puts several statements separated by semicolons one after another, with a blank line between them.
  • Leaves strings, quoted identifiers, comments and numbers exactly as you wrote them.

Choose the dialect

SQL is a family of languages rather than a single one. Each database adds its own keywords, functions, ways of quoting names and parameter markers. Selecting the right dialect, among standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle and BigQuery, helps the formatter recognise them, for example backticks in MySQL, square brackets in SQL Server or the double colon cast in PostgreSQL.

Keyword case and indentation

Most style guides write keywords in uppercase so that they stand out from table and column names, and some teams prefer lowercase. You can convert keywords to either or leave them as written. The indentation can be two or four spaces or a tab, to match your team's convention.

What it does not do

The formatter does not check that the SQL is correct for your database, that the tables exist or that the query will run. It changes layout only. Unusual syntax or vendor extensions may occasionally be laid out in a way you would not choose, or reported as an error you can fix by choosing another dialect. It does not optimise queries or rewrite them.

Frequently asked questions

How do I format an SQL query?
Paste the query, choose the dialect and copy the result. Each clause goes on its own line with consistent indentation.
Does formatting change what the query does?
No. Only whitespace and, if you choose, the case of keywords change. Strings, identifiers and values stay as written.
Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle (PL/SQL) and BigQuery.
Can I keep my keywords in lowercase?
Yes. Choose "lowercase" or "As written" under Keywords.
Why do I get an error for a valid query?
Unusual syntax or an extension of another database can confuse the formatter. Try a different dialect.
Is my SQL uploaded anywhere?
No. It is formatted in your browser.