Paste any SQL query below and click Format to get a clean, readable version with each major clause on its own line and consistent keyword casing — or click Minify to collapse it to a single line. Everything runs in your browser; nothing is uploaded.
SQL is one of the few languages that most teams write in three different places at once: application code, migration files, and ad-hoc queries in a database console. That makes it especially prone to inconsistent formatting — a 400-character one-liner pasted from a log here, a carefully indented CTE there. This free SQL Formatter turns any of it into a consistent, readable layout in one click: each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) gets its own line, every JOIN starts a new line, and AND/OR conditions are indented beneath the clause they belong to.
The formatter runs entirely in your browser with plain JavaScript — there is no API call, no upload, and no storage. It is also careful with your data: single-quoted string literals and double-quoted identifiers are treated as opaque tokens, so the values inside them are never re-cased or reflowed. Only unquoted SQL keywords are changed.
A query does not run any faster because it is pretty — but the humans who maintain it work dramatically faster when it is. Consistent formatting pays off in several concrete ways:
AND rewrites the entire line and hides the actual change.WHERE clause, an accidental cross join, or an OR that should have been an AND are far easier to spot when the logic is laid out vertically.SQL keywords are case-insensitive, so SELECT, select, and even SeLeCt all work. The choice is purely a style convention — but it is worth making deliberately:
Either choice is fine; mixing both in one codebase is not. Pick one, put it in your style guide, and use the keyword-case selector above to normalize existing queries. For a deeper look at the tradeoffs, see our guide on whether SQL keywords should be uppercase or lowercase.
This formatter follows the most widely adopted SQL layout: one major clause per line, with continuation conditions indented. For example:
SELECT o.id, o.total, c.name
FROM orders o
INNER JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'paid'
AND o.total > 100
ORDER BY o.created_at DESC
LIMIT 50The vertical structure mirrors how you reason about a query: what am I selecting, from where, joined to what, filtered how, ordered by what. Each question gets its own line.
Formatting arguments waste review time; conventions end them. The most effective setup is a short, written SQL style guide (keyword case, clause layout, alias rules, comma placement) combined with tooling that applies it automatically, so no one has to format by hand or nitpick in review. Use this tool to normalize one-off queries, and see our SQL formatting best practices and style guide for a template you can adopt as-is. If you review SQL regularly, our SQL code review checklist covers what to look for beyond formatting.
Sometimes you want the opposite of pretty: a compact single line. Minifying is useful when embedding SQL in a JSON config, a shell command, a log statement, or a code string where line breaks would need escaping. The Minify button collapses all whitespace runs to single spaces while leaving string literals untouched, so the query remains exactly equivalent.
Need to write a query from scratch? Try the SQL Generator, or paste a confusing query into the SQL Explainer. To go deeper, read SQL Formatting Best Practices & Style Guide, SQL Keywords: Uppercase or Lowercase?, and the SQL Code Review Checklist.