SQL Formatter

Paste a messy query and get clean, indented SQL with keywords on their own lines โ€” or minify it back to a single line. Runs entirely in your browser.

How to use the SQL formatter

  • Paste your query โ€” formatting happens as you type.
  • Choose whether keywords are UPPERCASE or lowercase, and your indent width.
  • Copy the clean version, or minify it back to a single line for a config file or log.

Why formatting matters

A long query written on one line is almost impossible to review. Putting each major clause โ€” SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY โ€” on its own line makes the structure obvious at a glance, so mistakes like a missing join condition or a misplaced filter jump out. Consistent capitalisation of keywords is the other half: it separates SQL syntax from your table and column names visually.

Benefits

  • Puts every major clause on its own line so query structure is obvious.
  • Choose UPPERCASE or lowercase keywords and your indent width.
  • Also minifies a query back to a single line.
  • Quoted strings and comments are preserved untouched.

Limitations to know

  • It formats structure โ€” it does not validate or lint your SQL.
  • Very complex nested subqueries are indented simply rather than fully nested.
  • It is dialect-agnostic, so vendor-specific syntax is passed through as-is.

Common mistakes to avoid

  • Expecting it to catch syntax errors โ€” that is your database's job.
  • Formatting a query with unbalanced quotes, which confuses any formatter.
  • Pasting production credentials in a comment before sharing the query.

Alternatives

For JSON use the JSON Formatter; to convert query results use the CSV to JSON Converter.

Last updated: August 2026 ยท Reviewed by the AI Toolbox editorial team.

Frequently asked questions

Is my query uploaded?

No โ€” formatting runs entirely in your browser. Nothing is sent to a server, so it's safe for queries containing schema names.

Which SQL dialects work?

It formats standard SQL structure, so MySQL, PostgreSQL, SQL Server, SQLite and similar all work fine.

Does it validate my SQL?

No โ€” it's a formatter, not a parser or linter. It won't tell you if a query is invalid.

Are strings and comments safe?

Yes โ€” quoted strings and comments are preserved untouched, so keywords inside them aren't reformatted.

Related tools