SQL Formatter

Beautify and indent SQL in your browser — clauses on their own lines, tidy keyword case.

100% Browser-Based • Local Processing
Indent
Keywords
Your SQL
Formatted
Formatted SQL appears here as you type.

Waiting for SQL Lines 0 Input 0 B Output 0 B

Privacy Focused

🔒 Local Processing. Your code never leaves your device.

Instant Results

🌐 Fully Client-Side. Runs instantly in your browser.

No Signup

⚡ No accounts. No API keys. Just open and use.

Browser Based

🚀 No installs, no CLI, no build step.

Beautify your SQL — readable and private

An SQL Formatter re-lays-out a messy query so each major clause — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY — sits on its own line with consistent indentation and tidy keyword case. This one runs entirely in your browser: it never runs your query, and your SQL is never uploaded.

A complex query crammed onto one line is painful to read and review. An SQL formatter fixes that by putting each major clause on its own line — SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY — indenting subqueries and JOIN conditions, and standardising keyword case so the structure of the query is obvious at a glance.

Paste your SQL or load a local .sql file, choose your indentation (2 spaces, 4 spaces or a tab) and a keyword case (UPPERCASE is traditional, because it makes the clauses stand out), and the query is re-laid-out as you type, with highlighting. Minify compacts it back to one line per statement, and Structure lists the clauses and the tables the query touches. Copy or download whichever you need.

The SQL formatter in dark mode: a one-line query in the cyan editor pane on the left with line numbers, and the magenta pane on the right showing it re-laid-out with SELECT, FROM, LEFT JOIN, ON, AND, WHERE, GROUP BY, HAVING and ORDER BY each on their own line and the qualified column names u.id and o.total intact
One clause per line, JOIN conditions indented under their JOIN, and every qualified name left exactly as written

Everything you typed comes back. The formatter reads the query with a real tokenizer rather than a pattern match, so a qualified name (u.name, db.schema.tbl), a two-character operator (>=, <>, !=, ||, ::), a bracketed or backtick-quoted identifier ([Order Details], `table`), a bind parameter (?, :id, $1, @x) and a temp table (#tmp) all survive it unchanged. String literals and comments are copied through byte for byte and are never re-cased — a keyword inside a string stays a string.

Privacy is especially important for SQL. Queries frequently reveal table and column names, business logic, and sometimes literal values — so it matters that everything here happens in your browser. There's no server, no upload, no logging, and no tracking, and, crucially, the tool never connects to a database or executes your query — it only re-lays-out the text. It works offline once loaded, and you can verify the lack of network calls yourself.

Two honest notes. Formatting is cosmetic: it changes layout and keyword case only, never what the query does or returns. And it is a beautifier, not a validator, linter or optimiser — it will not check your SQL against a schema, resolve a column name or improve performance. It does report the three things that are wrong in every dialect: a bracket that is never closed, a string literal that is never closed, and a block comment that is never closed. Beyond those, dialects differ (MySQL, PostgreSQL, T-SQL, SQLite, Oracle) and vendor-specific syntax may be laid out conservatively rather than idiomatically — but it is never rewritten.

For related data work, see the JSON Formatter, CSV to JSON, and JSON to CSV.

When an SQL formatter helps

  • Code review. Make a teammate's one-line query readable.
  • Debugging. See clauses and JOINs clearly to spot issues.
  • Documentation. Tidy queries before pasting into docs or tickets.
  • Learning. Understand a complex query by its structure.
  • Sensitive queries. Format SQL with private table names without uploading it.

How to format SQL

Paste or load your SQL

Type it, paste it, or open a local .sql file (read in-browser, not uploaded).

Choose indentation and keyword case

Indent is 2 spaces, 4 spaces or a tab, and shapes the formatted output only. Keywords is UPPERCASE, lowercase or As typed, and applies to SQL keywords only — your table names, column names and string values are left exactly as you wrote them, because those are case-sensitive in some databases and case-insensitive in others.

Format

There is no Format button: the output is rebuilt on every keystroke. Each major clause starts a line, a SELECT list gets one item per line, a JOIN keeps its ON and AND conditions indented beneath it, and a subquery in brackets becomes its own indented block. Each statement is separated from the next by a blank line.

Review preserved parts

Strings and comments come through byte for byte, and a -- comment always ends its line — putting one inline would comment out the SQL that followed it. Switch to Minify for one line per statement with comments removed, or Structure for a list of the clauses and the tables the query touches.

Copy or download

Grab the formatted (or compacted) query. Nothing is sent anywhere, and it's never run.

Realistic example

Paste select id,name from users u join orders o on o.user_id=u.id where u.active=1 order by name and it expands into clean, aligned clauses with uppercase keywords — id and name on their own lines under SELECT, and ON o.user_id = u.id indented under the JOIN. Switch to Minify and the same query comes back as one line with a single space only where two tokens would otherwise run together, which is what makes it a genuine size reduction rather than a re-spacing.

The same SQL formatter with Minify selected: the segmented control at the top reads Minify, the indent options are hidden, and the magenta pane holds the whole query on one line with single spaces only between words, ending in a semicolon
Minify puts one statement on one line and keeps a space only where two tokens would otherwise run together
Advanced tip

Uppercase keywords with each clause on its own line makes diffs and code review far clearer, which is why many style guides prefer it.

Common mistake to avoid

Do not expect the formatter to validate or run your SQL — it lays out whatever you give it, and an unclosed bracket produces a warning and formatted output, not a refusal. Test correctness against your database. The other one worth knowing: Minify removes comments. That is what minifying means, but if the comments are the documentation for a stored query, keep the original.

Related

Working with query results? Try CSV to JSON.

What to keep in mind

  • Zero-knowledge and private. Formatting runs in your browser — nothing uploaded, logged, or tracked, and it works offline.
  • It never runs your query. No database connection, no execution — it only re-lays-out the text.
  • Cosmetic only. It changes layout, not what the query does or returns.
  • Not a validator or optimiser. It won't check syntax against a DB, catch errors, or improve performance.
  • Dialects vary. MySQL, PostgreSQL, T-SQL, and Oracle differ; exotic syntax may format imperfectly, but strings and identifiers are preserved.

Frequently Asked Questions

The SQL formatter with Structure selected: the magenta pane lists the query clauses in order as small cards — SELECT, FROM with the table users, LEFT JOIN with the table orders, WHERE, GROUP BY, HAVING and ORDER BY
Structure answers what a query touches: every clause in order, and the table each one names
The SQL formatter on a 390-pixel phone: the Format, Minify and Structure buttons across the top, a two-button tab strip reading Your SQL and Result, and the formatted query filling the width with syntax colouring
On a phone the two panes become a tab strip and the mode buttons take the full width
How do I format an SQL query?

Paste your SQL (or open a local .sql file), choose an indentation and a keyword case, and each major clause — SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY — starts its own line, with the SELECT list one item per line, JOIN conditions indented under their JOIN, and any bracketed subquery as its own block. It happens as you type; there is no Format button. Then copy or download the result — nothing leaves your browser.

Does this upload my SQL, and does it work offline?

No upload, and yes it works offline. All formatting happens in your browser using JavaScript — there's no server receiving your query, no logging, and no tracking. That matters because SQL often contains private table and column names. Once the page has loaded it keeps working with no internet connection, which you can confirm in your browser's network tab.

Does it run my query or connect to my database?

No — never. The formatter only re-lays-out the text of your query; it doesn't connect to any database, execute anything, or touch your data. That means it can't return results, and it also can't leak data or cause side effects. It's purely a text-layout tool, which is exactly why it's safe to paste sensitive queries into.

Does formatting change what my query returns?

No. Formatting changes only whitespace, line breaks, and keyword case, none of which affect how SQL is parsed or executed — so the query means exactly the same thing and returns the same results. Keyword case is cosmetic (SQL keywords are case-insensitive), and identifiers and string literals are preserved verbatim. Your query behaves identically before and after.

Can I choose keyword case (UPPER vs lower)?

Yes. You can format keywords as UPPERCASE (the traditional, most readable convention that makes clauses stand out) or lowercase, depending on your style guide. It only affects SQL keywords like SELECT and WHERE — your table names, column names, and string values are left exactly as you wrote them, since those can be case-sensitive in some databases.

Which SQL dialects does it support?

It handles standard SQL and the common clauses across MySQL, PostgreSQL, SQL Server (T-SQL), SQLite and Oracle. There is no dialect selector, and it does not need one: the tokenizer accepts all five dialects' quoting at once — 'strings', "identifiers", `backticks`, [brackets] and Postgres $$ blocks — along with #temp tables, @variables and every bind-parameter style. Vendor-specific syntax it does not recognise is laid out conservatively rather than rewritten, so the query's meaning is unchanged either way.

What indentation should I use?

It's a style choice. 2 spaces keeps queries compact; 4 spaces is more spread out and can make nested subqueries clearer; a tab lets each editor set its own width. Indentation is purely cosmetic and doesn't affect the query, so pick whatever matches your team's conventions. Consistent indentation is what makes long queries with JOINs and subqueries readable.

Does it validate or optimise my SQL?

Almost no. It is a beautifier, not a validator, linter or optimiser: it will not check your SQL against a schema, resolve a column name, warn about a missing index or rewrite the query for performance. It does report three things, because they are wrong in every dialect and it has to tokenize the query anyway — a bracket that is never closed, a string literal that is never closed, and a block comment that is never closed. Each is a warning, not a refusal: the output is still produced. To validate or optimise properly, run the query against your database and use its planner (EXPLAIN).

Can it format very long or complex queries with subqueries and JOINs?

Yes — that's where it helps most. Long queries with multiple JOINs, nested subqueries, CTEs, and many conditions are exactly the ones that become unreadable on one line. The formatter indents subqueries and ON conditions to show their structure, so you can follow the logic. Because it runs locally, large queries are limited only by your device's performance.

Can I load a .sql file instead of pasting?

Yes. You can open a local .sql file and the tool reads it directly in your browser with the FileReader API — the contents load into the editor without being uploaded anywhere. This is handy for longer scripts or ones you'd rather not copy and paste, and it's exactly as private as pasting the query by hand.

Does it preserve strings and comments?

Yes, byte for byte. A string literal ('active', including one containing a quote written '' or a keyword such as 'from where') and both comment styles (-- ... and /* ... */) come through untouched and are never re-cased. One layout rule follows from that: a -- comment always ends its line, because anything placed after it on the same line would be inside the comment. Minify is the exception and removes comments on purpose — that is what minifying means.

Is it free, and are there limits?

Yes, completely free — no payment, no signup, no account, and no usage caps or watermarks. Since everything runs in your browser, there's nothing for us to meter; the only practical limit is your device's performance on very large queries. Use it as much as you like, including offline once the page has loaded.

What does the Structure view show?

It lists the query’s clauses in order and, for each one that names a table — FROM, every kind of JOIN, INSERT INTO, UPDATE, DELETE FROM, CREATE TABLE and friends — the table it names, qualified as written (db.schema.orders). It is the quickest way to answer “what does this query actually touch?” about a long one someone has handed you, and to spot a JOIN against a table you did not expect. It reads the same tokens the formatter does, so a subquery in the FROM position is reported as one rather than guessed at.

Still have questions?

If you can't find the answer you're looking for, feel free to contact our support team.

Contact Us