SQL Formatter
Format SQL queries with consistent indentation and keyword casing. Supports MySQL, PostgreSQL, and standard SQL.
How to use SQL Formatter
- 1Paste SQL
Paste the query you want to format.
- 2Click Format
Indented, uppercased-keyword SQL appears in the output pane.
About SQL Formatter
SQL queries — especially the multi-join, subquery-heavy ones generated by ORMs or written by junior teammates — can easily span several hundred characters on a single line with wildly inconsistent capitalization. A formatter rewrites the query with consistent indentation, line breaks at major clauses (SELECT, FROM, WHERE, JOIN), and a chosen keyword case.
Readable SQL is debuggable SQL: you can spot a missing JOIN condition, an accidental Cartesian product, or a WHERE clause that filters the wrong table much faster when the structure is visible. Utilify formats Standard SQL, MySQL, PostgreSQL, SQLite, MS SQL, and BigQuery — everything happens in your browser, so even queries that reference production schema details stay private.
The convention of uppercasing keywords (SELECT, FROM, WHERE) while leaving identifiers (table and column names) in their natural case is the most widely used SQL style. It creates an instant visual separation between the language and your data: your eye learns to skim the uppercase words as structure and the lowercase words as content. If your team prefers all-lowercase keywords, the case toggle switches the whole query in one click.
Formatting is purely cosmetic — it never changes what the query does. The tool reflows whitespace and casing but leaves the logic, table names, literals, and clause order untouched, so the formatted query returns exactly the same result set as the original. That makes it safe to run on anything: a one-liner copied from a log, a generated migration, or a 200-line analytics report.
A readable layout also pays off in code review and version control. When every query in your migrations and seed files follows the same indentation and casing, diffs highlight real logic changes instead of drowning them in reformatting noise — and a reviewer can scan a complex join at a glance instead of mentally re-indenting it first.
MySQL vs PostgreSQL vs SQL Server — the differences that break copy-pasted queries
Formatting is dialect-agnostic, but running the query is not. These are the differences most likely to bite when a query written for one database is pasted into another:
| MySQL | PostgreSQL | SQL Server (T-SQL) | |
|---|---|---|---|
| Identifier quoting | `backticks` | "double quotes" | [square brackets] |
| String comparison | Case-insensitive by default (…_ci collations) | Case-sensitive | Collation-dependent, commonly case-insensitive |
| Row limiting | LIMIT 10 OFFSET 20 | LIMIT 10 OFFSET 20, or FETCH FIRST | TOP 10, or OFFSET … FETCH NEXT |
| Auto-increment column | AUTO_INCREMENT | GENERATED … AS IDENTITY (or legacy SERIAL) | IDENTITY(1,1) |
| String concatenation | CONCAT() — || needs PIPES_AS_CONCAT mode | || operator | + operator or CONCAT() |
The formatter accepts all of these dialects — the table is about executing the query, not formatting it.
When to use SQL Formatter
- Reviewing ORM output
ORMs like Prisma and Hibernate produce minified, hard-to-read SQL. Format before reviewing.
- PR code review
Reformat raw SQL in migrations or seed files before committing for cleaner diffs.
- Learning SQL
Format example queries from tutorials to see clause structure clearly.
Examples
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc limit 10
SELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = 1 GROUP BY u.id, u.name ORDER BY orders desc LIMIT 10
SQL mistakes that formatting makes visible
- Double quotes around string literals
In standard SQL and PostgreSQL, double quotes mean identifiers and single quotes mean strings. MySQL by default tolerates double-quoted strings, so a query that works in MySQL can suddenly mean "compare against a column named active" when pasted into Postgres. Always use single quotes for string values.
WHERE status = "active" -- MySQL: string · Postgres: column reference WHERE status = 'active' -- correct everywhere - Comparing to NULL with =
NULL is not a value — WHERE col = NULL is never true in any dialect because NULL comparisons yield UNKNOWN, not TRUE. Use IS NULL / IS NOT NULL. The same three-valued logic makes NOT IN return zero rows when its subquery contains a single NULL.
WHERE email = NULL -- matches nothing, silently WHERE email IS NULL -- correct - Accidental Cartesian products hiding in one-liners
A comma-style FROM users, orders with a forgotten join condition multiplies every row of one table by every row of the other. On a 300-character single line, the missing ON is invisible — after formatting puts each JOIN on its own line, it jumps out. This is the single best reason to format a query before reviewing it.
- Relying on MySQL’s old GROUP BY leniency
Selecting columns that are neither aggregated nor in GROUP BY errors out in PostgreSQL and in MySQL 5.7+ (ONLY_FULL_GROUP_BY is the default). Queries written against older, lenient MySQL configurations break on migration — aggregate the column or add it to GROUP BY.
Frequently asked questions
Which SQL dialects are supported?+
Standard SQL, MySQL, PostgreSQL, SQLite, MS SQL, and BigQuery.
Can I lowercase keywords?+
Yes — use the case toggle to switch all keywords between upper and lower case in one click.
Does formatting change what my query returns?+
No. Formatting only reflows whitespace and keyword casing. The logic, table names, literals, and clause order are untouched, so the result set is identical.
Is my query sent to a server?+
No. Formatting runs entirely in your browser, so queries that reference production schema or sensitive table names stay on your device.
Why uppercase keywords?+
Uppercasing keywords while leaving identifiers in their natural case visually separates the SQL language from your data, making complex queries far easier to scan. It is a convention, not a requirement — toggle it off if you prefer lowercase.
Related tools
Format, beautify, and validate JSON online. Free, fast, runs entirely in your browser.
Validate JSON syntax online with clear error messages and line numbers. Free and private.
Encode and decode Base64 strings online. UTF-8 safe, browser-only — your data never leaves your device.
From the blog
We measured catastrophic backtracking in Node 20: /^(a+)+$/ takes 6.5 seconds at 30 characters and doubles with each one added. Why it happens, the outages it caused at Stack Overflow and Cloudflare, and how we patched our own regex tester.
Real numbers from Node 20 on an M2 Pro: 24M v4/sec vs 2.7M v7/sec, why v7 is only 50% sorted in bursts, and a 35× index-locality gap. Code included.