AIWalay Tools

SQL Formatter

Format SQL queries with clause line breaks, keyword casing and your choice of dialect and indentation. Handles subqueries and joins. Copy or download.

About the SQL Formatter

This SQL formatter turns dense, one-line queries into clean, readable SQL. Paste a SELECT with a dozen joins and conditions, and it breaks each major clause — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY and more — onto its own line, indents the select list and conditions, and uppercases keywords consistently.

It tokenizes strings, quoted identifiers and comments before formatting, so your literals and column names are never altered. Subqueries are detected and indented as nested blocks, JOINs and their ON clauses line up, and comma-separated select columns each get their own line for easy scanning and diffing.

Choose your dialect — standard/PostgreSQL, MySQL or SQL Server — to get the right identifier-quoting rules (backticks for MySQL, square brackets for T-SQL), pick 2-space, 4-space or tab indentation, and set keywords to upper or lower case. Copy the result or download it as .sql. It all runs locally in your browser.

How to Use the SQL Formatter

  1. 1Paste your SQL query into the input box.
  2. 2Choose the dialect, indentation and keyword casing.
  3. 3Click Format SQL.
  4. 4Copy the formatted query or download it as a .sql file.

Frequently Asked Questions

Why does the dialect setting matter?

Different databases quote identifiers differently: MySQL uses backticks, SQL Server uses square brackets, and standard SQL/PostgreSQL use double quotes. Selecting the right dialect ensures the formatter treats those quoted identifiers as single tokens instead of breaking them.

Will formatting change my query's results?

No. The formatter only adjusts whitespace, line breaks and keyword casing. It never reorders clauses, rewrites expressions or touches your string literals and identifiers, so the query is functionally identical.

Does it handle subqueries and CTEs?

Yes. Parenthesised subqueries that start with SELECT are detected and indented as nested blocks, and clause keywords like WITH, JOIN and ON are broken onto their own lines so complex queries become far easier to read.

Is this a linter or a query validator?

It's a formatter, not a validator. It makes SQL readable but doesn't check that tables and columns exist or that the syntax is fully valid for your database. Run the query against your database (or a linter) to confirm correctness.

Related Tools