Skip to content
AllToolsDesk

Popular

  • JSON Formatter & ValidatorFormat, minify and validate JSON with error locations.
  • CSS FormatterBeautify CSS, SCSS and Less with Prettier.
  • CSS MinifierCompress CSS and see the bytes saved.
  • JavaScript FormatterBeautify JavaScript and TypeScript.
  • JavaScript MinifierMinify JavaScript with Terser.
  • HTML FormatterIndent HTML, including inline CSS and JS.
  • JPG to PDFTurn images into a PDF, one per page.
  • Merge PDFCombine several PDFs into one file.
38 free toolsSee all tools

SQL Formatter

Format messy SQL into readable, consistently indented queries. Supports standard SQL, MySQL, PostgreSQL, SQL Server and SQLite.

Runs in your browser. Nothing is uploaded.

Ready.

About the SQL Formatter

Queries generated by ORMs, logged by a database or written in a hurry are often one long line, which makes joins, conditions and subqueries hard to follow. Formatted SQL puts each clause on its own line and indents nested parts, so you can see the logic of the query at a glance.

Consistent formatting also makes code reviews and diffs clearer and helps when you share a query with colleagues. Choosing your database dialect lets the formatter understand its syntax, such as backtick identifiers in MySQL, square brackets in SQL Server or :: casts in PostgreSQL. The query is only rewritten for readability; it is never executed.

How to use the SQL Formatter

  1. 1

    Paste a query into the input panel, open a .sql file, or load the sample. It is formatted straight away.

  2. 2

    Pick the dialect your database uses so its syntax (backticks, square brackets, :: casts and so on) is understood.

  3. 3

    Choose how keywords are written and the indent size. The output updates when you change an option.

  4. 4

    If the query cannot be parsed, the status bar shows the line and column. Use “Go to error” to jump to it.

  5. 5

    Copy the result or download it as a .sql file.

Examples

1Break a one-line query into clauses
Before
select id, name from users where active = 1 order by name
After
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name
2Indent a subquery
Before
select * from orders where customer_id in (select id from customers where country = 'NL')
After
SELECT
  *
FROM
  orders
WHERE
  customer_id IN (
    SELECT
      id
    FROM
      customers
    WHERE
      country = 'NL'
  )

Good to know

  • Formatting only: the query is not run or checked against your schema, so a misspelt table name is not reported.
  • Comments are kept, but their position may move to the start of the line.
  • Vendor-specific procedural code (PL/pgSQL bodies, T-SQL control flow) is formatted as plain statements and may not look ideal.

Frequently asked questions

Which SQL dialects are supported?

Standard SQL, MySQL (also fine for MariaDB), PostgreSQL, SQL Server (T-SQL) and SQLite. Choosing the right dialect matters for quoting rules and operators that only some databases have.

Does formatting change what my query does?

No. Only whitespace, line breaks and, if you choose, the case of keywords change. Identifiers, strings and values are left exactly as written.

Can I format several statements at once?

Yes. Separate them with semicolons and each statement is formatted in turn, with a blank line between them.

Is my code uploaded to a server?

No. Processing happens entirely in your browser, in a background thread. Your input is never sent to our servers or stored anywhere.

More tools that pair well with this one.

Browse all tools