MikroBI Robot Logo

MikroBI | DevKit

database

SQL Formatter

Format and beautify raw SQL queries, or compact them back down, entirely in your browser.

Related tools

About this tool

SQL that comes out of an ORM, a slow query log, or a colleague's Slack message is often one dense, unbroken line — every SELECT, JOIN, and WHERE condition run together with no visual structure to lean on. That's fine for a database engine, which doesn't care about whitespace, but it's genuinely hard for a human to scan: finding the join condition that's missing an index, or spotting which WHERE clause is filtering out the rows you expected, means reading character by character instead of at a glance. This tool takes that wall of text and reflows it into the shape SQL is usually written in by hand — one clause per line, columns and SET assignments listed vertically, conditions indented under WHERE.

Formatting works by recognizing the standard clause keywords (SELECT, FROM, WHERE, JOIN and its variants, GROUP BY, ORDER BY, HAVING, LIMIT, INSERT INTO, VALUES, UPDATE, SET, and so on) and starting a new line at each one, while AND/OR conditions inside a WHERE clause get indented a level further so the logical grouping is visible. Column lists after SELECT, and assignment lists after SET, are split one-per-line at their top-level commas — but a comma inside a function call like COALESCE(a, b) or a subquery is left alone, since splitting inside parentheses would just make things harder to read, not easier. String and quoted-identifier literals are tracked separately from the rest of the query, so a keyword that happens to appear inside a string (or a table/column name that happens to match a clause word) is never mistaken for actual SQL syntax.

Minifying does the reverse: it strips the tool's own indentation and line breaks (and any extra whitespace from however the query was originally written) down to a single compact line with normalized single spaces between tokens. That's useful when you need to paste a query into a place that doesn't handle multi-line text well — a one-line config value, a shell command, or a log message — without changing what the query actually does.

This is a formatter, not a query validator or a database client: it doesn't check your SQL against any particular database's grammar, doesn't execute anything, and won't catch a genuine syntax error the way a real parser would. What it will do reliably is turn any reasonably standard SQL — across MySQL, PostgreSQL, SQLite, SQL Server, and similar dialects, since the core clause keywords are shared — into a readable, consistently indented version without altering the query's meaning, all locally in your browser with nothing sent to a server.

Because everything runs client-side, it's safe to paste real, unmodified queries pulled from a production slow-query log or an internal migration script, even ones referencing internal table and column names you wouldn't want to send to a random website. Once you have a formatted or minified result, copy it directly, or use the “Send to” button to hand it to another tool in this toolbox — for example, checking its length or diffing two versions of the same query against each other.

Frequently asked questions

Does this tool validate my SQL or connect to a database? expand_more

No. It's a text formatter, not a parser or a database client — it doesn't check your query against a specific database's grammar and never executes anything. It only reflows whitespace and line breaks around recognized clause keywords.

Will formatting change what my query actually does? expand_more

No. Only whitespace, indentation, and line breaks change. Keywords, identifiers, literals, and punctuation are preserved exactly, so the formatted query is functionally identical to the original.

Does it handle commas inside function calls correctly? expand_more

Yes. Commas inside parentheses — for example the arguments to COALESCE(a, b) or a subquery — are left on the same line. Only top-level commas in a SELECT column list or a SET assignment list are split onto their own lines.

Which SQL dialect does this support? expand_more

The formatter recognizes standard clause keywords shared across MySQL, PostgreSQL, SQLite, SQL Server, and similar dialects (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, INSERT INTO, UPDATE, and more). It isn't dialect-specific, so dialect-only syntax may not be reflowed as cleanly.

Is it safe to paste a real production query here? expand_more

Yes. Formatting and minifying both run entirely in your browser — nothing is uploaded to a server — so it's safe to use with queries referencing real table names, column names, or values you wouldn't want to send elsewhere.