Skip to main content
ToolsHub

SQL Formatter

Paste messy SQL and get a clean, indented query with capitalized keywords and clause line breaks. Great for code reviews and documentation — all client-side.

Updated

Files never leave your browser

Formatted SQL will appear here

Paste a SQL query on the left to get a cleanly formatted version.

How to use SQL Formatter

The SQL Formatter beautifies and reformats SQL queries by adding consistent indentation, capitalising reserved keywords, inserting line breaks between clauses, and aligning columns in SELECT lists. Well-formatted SQL is dramatically easier to read during code review, debug in query analysers, and document in runbooks. The formatter supports multiple dialects including ANSI SQL, MySQL, PostgreSQL, T-SQL (SQL Server), and BigQuery, running entirely in your browser.

  1. Paste your raw or minified SQL query into the input area.
  2. Select the SQL dialect from the dropdown (ANSI, MySQL, PostgreSQL, T-SQL, BigQuery, etc.).
  3. Choose indentation style: 2 spaces, 4 spaces, or tab.
  4. Select keyword casing: UPPERCASE (most common), lowercase, or Capitalized.
  5. Click Format to produce the beautified output.
  6. Copy the formatted SQL or use the Minify button to collapse it back to a single-line version for embedding in strings.

Your data never leaves your device — 100% private processing.

SQL formatting conventions that aid readability

The most widely adopted SQL style places each major clause on its own line (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT), indented consistently. Expressions within SELECT are each placed on a new indented line with the comma at the start, making it easy to comment out individual columns without touching other lines. Subqueries are indented one extra level relative to the outer query. JOIN conditions follow the JOIN keyword on the next line with an ON or USING clause. Consistent keyword casing (all uppercase is the traditional convention) distinguishes SQL keywords from identifiers at a glance.

SQL formatting before and after
FormatExample
Unformattedselect u.id,u.name,o.total from users u join orders o on u.id=o.user_id where o.total>100 order by o.total desc
FormattedSELECT\n u.id\n , u.name\n , o.total\nFROM users u\nJOIN orders o ON u.id = o.user_id\nWHERE o.total > 100\nORDER BY o.total DESC

SQL dialect differences to watch for

While core DML (SELECT, INSERT, UPDATE, DELETE) is nearly universal across dialects, important differences exist. MySQL uses backtick (`) for identifier quoting; PostgreSQL and ANSI SQL use double quotes ("); T-SQL uses square brackets ([]). String concatenation is || in ANSI/PostgreSQL but + in T-SQL and CONCAT() in MySQL. The LIMIT clause is MySQL/PostgreSQL syntax; T-SQL uses TOP N or OFFSET/FETCH NEXT; Oracle uses ROWNUM or FETCH FIRST N ROWS ONLY. Boolean literals TRUE/FALSE are ANSI and PostgreSQL; MySQL accepts them but T-SQL uses 1/0. Always specify your target dialect so the formatter applies the correct quoting and syntax conventions.

Worked examples

Format a one-liner

Inputs: select id,name from users where id=1

Result: SELECT / FROM / WHERE on separate lines, keywords uppercased

Keyword casing

Inputs: lowercase keywords

Result: SELECT, FROM, WHERE uppercased; identifiers untouched

Minify back

Inputs: formatted multi-line query

Result: single-line query — identical result rows

Glossary

DML
Data Manipulation Language — the SQL subset covering SELECT, INSERT, UPDATE, DELETE, and MERGE.
DDL
Data Definition Language — the SQL subset covering CREATE, ALTER, DROP, and TRUNCATE for schema objects.
CTE
Common Table Expression — a named temporary result set defined with WITH ... AS (...) that simplifies complex queries.
Window function
A SQL function (RANK, ROW_NUMBER, LAG, SUM OVER) that operates over a partition of rows without collapsing them into a single output row.
Execution plan
The sequence of operations the database engine uses to satisfy a query; formatted SQL is easier to correlate with plan output.

Related reading

Free · No spam

Get weekly tool tips & updates

New tools, power-user tips, and productivity hacks — delivered free every Friday.

No spam, ever. Unsubscribe with one click.

Related Developer Tools

Explore all Developer Tools.