Home / Formatters & Validators / SQL Formatter

SQL Formatter

Runs in your browser Files stay on your device · 100% private

Readable SQL in one click.


    

About SQL Formatter

An SQL formatter rewrites a query with consistent indentation so you can read it. Paste a long statement dumped from a log file or a migration script and the output puts select lists on separate lines, starts joins and where clauses on their own lines, indents AND conditions, and opens subqueries and CASE expressions into readable blocks. Comments stay attached to the place they were written. You can also strip everything back to a single line with Minify, choose Standard SQL, SQLite, PostgreSQL, or MySQL, and choose whether keywords are uppercased, lowercased, or left as typed. Parsing happens in your browser, so queries containing real table and customer names stay on your machine.

How to Use SQL Formatter

1

Paste your query

Drop the SQL into the Input SQL box and the formatted result appears automatically as you type. Click Sample to load a multi-join example if you want to see the layout first.

2

Choose dialect, indentation, and keyword case

Use the dropdowns to pick Standard SQL, SQLite, PostgreSQL, or MySQL, then set Indent 2 spaces, Indent 4 spaces, or a tab. MySQL additionally treats # as the start of a comment.

3

Click Format or Minify

Format produces the readable layout. Minify collapses the statement onto one line and drops comments, which is handy for a log entry or a command line.

4

Copy or download

Click Copy to put the result on your clipboard, or Download to save it as query.sql. A status line under the boxes reports the character count, line count, and token count.

Why Use SQL Formatter: Common Use Cases

Reading a query from a slow query log

Server logs often print queries on a single line. Formatting them back into their clause structure makes it obvious where a join or a filter went missing.

Cleaning up generated migrations

Schema tools emit long INSERT and CREATE statements without line breaks. Formatting them makes a migration file reviewable in a pull request.

Comparing two versions of a query

Format both versions before checking them so line breaks no longer hide a real difference. Use a text diff tool to see the changes.

Sharing a query in a bug report

A formatted query is far easier for someone else to review than a wall of text, and it fits in a ticket description without losing its structure.

SQL Formatter Specifications

Input Formats SQL text
Output Formats Formatted SQL, Minified SQL
File Size Limit No strict limit (dependent on device memory)
Processing Engine 100% Client-side (Runs locally in your browser)
Data Retention Files never leave your device
Batch Processing Single file processing

Tips for SQL Formatter

  • For a database dump rather than a single statement, convert it with CSV to JSON or reshape it using Excel to CSV.

  • The tool reads structure, not table names. If a column name is a reserved word in your database, keep the original casing by choosing Keep as typed in the keyword case dropdown.

  • Formatting does not validate your schema. If a query parses but returns nothing, check the identifiers with Regex Tester or extract the data first with XML to JSON.

  • Style differences between team members are a common source of noisy diffs. Agree on one indentation setting here and add it to your editor config so both sides match.

  • Nested CASE expressions indent one level per block. If a deeply nested query gets hard to follow, break it into separate statements or use a view.

Frequently Asked Questions

Does the SQL formatter change my query so it runs differently?

It does not touch identifiers, values, operators, or comment text. It only changes whitespace, indentation, and keyword capitalization according to your dropdown choice. A formatted query executes the same as the original.

How do you handle semicolons and multiple statements?

Each statement ends on its own line with its semicolon attached, so a script containing several statements formats into readable blocks instead of one long run. Only the text after the last complete statement is treated as a new query.

Can it format SQL comments?

Yes. Double dash comments and block comments are kept, and a comment that was written on its own line stays on its own line. Comments placed after code on the same line stay there too. Minify is the one mode that removes them.

What does Minify actually remove?

It drops comments and all unnecessary whitespace, then joins the remaining tokens into a single line. Spacing inside identifiers, around the equals sign, and inside parentheses is preserved so the query still parses.

Is my SQL query uploaded anywhere?

No. The formatter tokenizes and rebuilds the text in your browser, so a query containing production table names or customer data is never transmitted. You can disconnect from the internet after the page has loaded and it still works.

What happens if my query has a syntax error?

You get a message naming the problem, such as an unclosed string or a parenthesis without a pair, together with the line number where it starts. Fields with names like select, from, and join are treated as keywords, so an unquoted column that collides with one will be capitalized but still readable.