SQL Formatter
Format messy SQL into readable, indented queries — or minify it back to one line.
A query that arrives as one unbroken line — out of a log file, an ORM, or a colleague’s chat message — is hard to read and harder to debug. Formatting is a mechanical job: put each major clause (FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT) on its own line, make the keywords consistent in case, and the structure of the query becomes visible at a glance. That is exactly what this page does, in your browser.
This is a formatter, not a validator: it lays out the SQL you give it but does not check it against any database, and it will happily lay out SQL with a mistake in it. Your SQL is formatted in this browser only — nothing is uploaded.
Quick answers
How do I format SQL online?
Paste the query into a formatter and it re-lays the text with a line break before each major clause (FROM, WHERE, JOIN, ORDER BY…) and consistent keyword case. Here the sample one-liner comes out as six readable lines.
Formatting changes whitespace only — never the meaning of the query — and it is not validation: the tool cannot know whether your tables or columns exist.
Should SQL keywords be uppercase or lowercase?
Either is valid SQL; uppercase keywords against lowercase identifiers is the most common convention because it makes the structure scannable. This page can apply uppercase, lowercase, or leave your keywords exactly as written.
Consistency matters more than the choice itself — a codebase that mixes both at random is the only genuinely bad option.
How to use
- Paste your SQL into the top box — a single-line export, a copied query, anything.
- Choose the keyword case (UPPERCASE is the common convention) and an indent width.
- Read the formatted query below, with each major clause on its own line, then copy it.
- Use Minify when you need the opposite: one line, for a config value or an embedded query string.
About this tool
Two honest limits. First, this is a formatter, not a parser: it recognises the standard clause keywords and re-lays the text around them, but it does not build a syntax tree, so an exotic dialect construct may not break exactly where a database-specific tool would break it. Second, it is not a validator — it never connects to a database and cannot tell you whether the query will run. `SELECT` laid out beautifully can still name a table that does not exist. For a worked sense of scale: the sample query above, one line as pasted, comes out as six lines with the clauses stacked, which is the shape most style guides ask for.
Frequently asked questions
Does this formatter work for MySQL, PostgreSQL and SQL Server?
It formats the clause structure they all share — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT and friends — which is most of what makes a query readable. It does not apply dialect-specific rules, so a construct unique to one engine is laid out by the general rules rather than that engine’s own style.
Will the formatter catch errors in my SQL?
No. It rearranges whitespace and keyword case only; it does not parse the query against a schema or run it. A missing comma survives formatting untouched — formatting makes errors easier for you to spot, it does not spot them for you.
What is the difference between Format and Minify?
Format expands the query across lines, one clause per line, for humans to read. Minify does the reverse — every run of whitespace becomes a single space and the query comes out as one line, which is what you want for a config value or a query embedded in a URL or JSON string. The words of the query are identical either way.
Is my SQL uploaded anywhere?
No. The formatting runs in JavaScript in this page; the SQL you paste — however sensitive the table names — never leaves your device, and there is no share link for text tools on this site for exactly that reason.
First time embedding? Read the step-by-step guide →
More free tools
UUID Generator
Generate random v4 UUIDs in bulk.
JSON Formatter & Validator
Format, minify and validate JSON in one click.
What Is My IP
See your public IP address instantly. No sign-up, nothing stored.
Regex Tester
Test, check and validate regular expressions with live highlighting.
JWT Decoder
Decode a JWT token without the secret — see its header and payload.
SHA-256 Hash Generator
Generate SHA-256 / SHA-512 hashes instantly.