Free tool
Free SQL formatter
This free SQL formatter turns a wall of unindented, single-line SQL into clean, readable queries in one click. Choose your dialect, keyword case, and indent style, then format, minify, copy, or download the result. Everything runs locally in your browser — nothing is ever uploaded to a server.
SQL formatter & beautifier
Format, beautify, and minify SQL for six dialects — right in your browser, with no upload and no size limit.
Keyword case
Indent
0 B
0 B
Everything runs locally in this browser tab using the open-source sql-formatter library. Your queries are never uploaded to a server, so this works offline and stays completely private — safe for queries containing table names, business logic, or other sensitive schema details.
How to format SQL online
- Paste or upload your query. Drop raw SQL into the input box, or upload a
.sqlor.txtfile — no size limit, no sign-up. - Pick a dialect. Choose Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL, or BigQuery so dialect-specific syntax (backticks,
TOP, array literals, and so on) parses correctly. - Set keyword case and indent. Toggle keywords to UPPERCASE, lowercase, or leave them as typed, and choose 2- or 4-space indentation.
- Format, copy, or download. Click Format SQL to beautify the query, then copy the result or download it as a
.sqlfile. Need the opposite? Hit Minify to collapse everything back to a single compact line.
Because formatting happens entirely on your device using the open-source sql-formatter library, there is no upload step, no waiting on a server, and no limit on how many queries you can format.
Why format SQL in the first place?
SQL is unusually forgiving about whitespace — a query with every clause jammed onto one line runs exactly the same as one that is neatly indented. That flexibility is exactly why formatting matters: nothing forces consistency, so without a formatter every developer, every ORM-generated query, and every copy-pasted snippet from Stack Overflow ends up looking different. A SQL beautifier gives you back that consistency for free.
- Readability. A query with ten joins and three subqueries is nearly impossible to audit as one line. Breaking it into clauses — one
SELECT, oneFROM, oneWHEREper line — makes the logic visible at a glance. - Faster debugging. When a query returns the wrong rows, a formatted layout makes it far easier to spot a misplaced
AND/OR, a missing join condition, or an accidentally cross-joined table. - Cleaner diffs and code review. Consistent formatting means pull requests show the actual logic change, not a wall of whitespace noise, which makes SQL migrations and stored procedures much easier to review.
- Easier onboarding. New team members read formatted queries faster than compressed ones, especially in analytics repos where queries are often hundreds of lines long.
- Safer copy-paste. Query builders, BI tools, and ORMs (Django, Sequelize, Prisma, Rails) frequently log or export SQL as one dense line. Formatting it before you paste it into a ticket, a Slack thread, or documentation keeps everyone on the same page.
SQL style conventions this formatter follows
There is no single official SQL style guide — every company and every open-source project seems to have slightly different conventions — but most style guides (Mozilla, GitLab, Simon Holywell's widely cited SQL Style Guide) converge on a few shared ideas that this tool applies:
- One major clause per line.
SELECT,FROM,WHERE,GROUP BY,HAVING,ORDER BY, andLIMITeach start a new line, so the shape of the query is visible without reading every token. - Consistent indentation. Columns in a
SELECTlist, conditions in aWHEREclause, and nested subqueries are indented relative to their parent clause — 2 spaces is the most common default, though 4 spaces is popular in enterprise codebases. - Joins on their own line. Each
JOIN(and itsONcondition) gets its own line rather than being crammed after the previous clause, which matters most in queries with five or more joined tables. - Predictable comma placement. Whether commas go at the end or the start of a line is mostly a matter of team preference — this formatter uses trailing commas, the more common convention in modern SQL style guides.
- Blank lines between statements. When a file contains multiple statements — a common pattern in migration scripts and seed files — a blank line (or two) between them keeps each query visually separate. You can control exactly how many with the “Lines between queries” setting.
The keyword case debate: UPPERCASE, lowercase, or preserve?
Few SQL topics generate more good-natured disagreement than keyword casing. There is no technical reason to prefer one over another — SQL keywords are case-insensitive in every mainstream database — so the “right” choice comes down to team convention and readability preference.
| Style | Looks like | Why teams pick it |
|---|---|---|
| UPPERCASE | SELECT id FROM users WHERE active = TRUE | The traditional convention going back to early relational databases. Keywords visually separate themselves from table and column names at a glance, which helps in long queries. |
| lowercase | select id from users where active = true | Increasingly popular in modern data teams and dbt-style analytics engineering, where SQL is treated more like application code and consistent lowercase feels less “shouty.” |
| Preserve | Select id From users Where active = True | Leaves keywords exactly as typed. Useful when you only want indentation fixed and don't want the formatter to touch casing — for example when a linter or existing codebase already enforces its own rule. |
Whichever you pick, the important thing is consistency across a codebase — mixed casing is what actually hurts readability, not the choice itself. This tool lets you switch instantly so you can match whatever convention your team already uses.
SQL dialect differences this formatter handles
“SQL” is really a family of closely related but not identical languages. A query that parses fine in PostgreSQL can throw a syntax error in T-SQL, and vice versa. That is why this formatter lets you pick a specific dialect instead of assuming one universal grammar:
- Standard SQL — the ANSI baseline. Good default when you are not targeting a specific engine or are writing portable SQL.
- MySQL — supports backtick-quoted identifiers,
LIMIT offset, countsyntax, and MySQL-specific functions likeIFNULLandGROUP_CONCAT. - PostgreSQL — adds array types,
JSONBoperators (->,->>),ILIKE, and window function extensions that other dialects don't recognize. - SQLite — a lighter grammar with a few of its own quirks, like flexible typing and
INSERT OR REPLACE. - SQL Server (T-SQL) — uses
TOP ninstead ofLIMIT, square-bracket[identifiers], and procedural extensions likeDECLAREandBEGIN...END. - BigQuery — Google's dialect adds backtick-quoted fully qualified table paths (
`project.dataset.table`),STRUCT/ARRAYtypes, and its own set of analytic functions.
If a query fails to parse under the selected dialect, the tool still shows a best-effort formatted result along with a plain-language message — try switching dialects first, since a mismatched dialect is the most common cause of a parse error.
Common SQL formatting mistakes to avoid
Beyond picking a dialect and a keyword case, a few habits separate genuinely readable SQL from SQL that is merely indented. Watch for these when you review formatted output:
- Burying join conditions. Writing joins as implicit comma-separated tables in the
FROMclause with conditions tucked intoWHEREwas standard practice decades ago, but explicitJOIN ... ONsyntax is far easier to format, read, and audit for accidental cross joins. - Over-nesting subqueries. A formatter can indent a deeply nested subquery cleanly, but that doesn't make it easy to read. If a query needs three or more levels of nesting, a common table expression (
WITHclause) usually communicates intent better and formats more predictably. - Inconsistent aliasing. Mixing
ASand bare aliases, or aliasing some columns but not others, makes formatted output look inconsistent even when indentation is perfect. Decide on one convention and apply it throughout the query. - Ignoring line length. A single
WHEREcondition with sixANDs chained on one line defeats the purpose of formatting. Breaking boolean conditions onto their own lines — one predicate per line — keeps even complex filters scannable. - Formatting after the fact, every time. Running a formatter once on a legacy file helps, but the real value comes from formatting consistently as part of your workflow — before every commit, or as a pre-commit hook — so formatting differences never show up as noise in a diff.
None of these are enforced by the SQL language itself, which is exactly why a formatter is useful: it takes team conventions that would otherwise live only in a style guide document and applies them automatically, every time, without a reviewer having to leave a comment about spacing instead of logic.
Who uses a SQL formatter?
- Backend & data engineers clean up auto-generated ORM queries and long analytics queries before committing them to a repo.
- Analysts & data scientists tidy ad-hoc queries pulled from a BI tool or notebook before sharing them with a teammate.
- DBAs reformat queries pulled from slow-query logs to make them easier to read during performance tuning.
- Students & bootcamp learners use consistent formatting to build good habits early and make their own queries easier to debug.
- Technical writers format SQL examples for documentation, blog posts, and tutorials so code blocks look professional and are easy to scan.
- Interviewers & candidates paste interview SQL questions and answers into a shared format to reduce friction when reviewing solutions.
Formatting tips for cleaner SQL
- Alias every joined table with something short and meaningful (
ofor orders,cfor customers) — it keeps formatted output compact without sacrificing clarity. - Format before you optimize. A cleanly indented query makes it far easier to spot a missing index candidate or an unnecessary subquery.
- Keep
SELECT *out of production queries — list columns explicitly so a formatted diff actually shows which fields changed. - For migration files with many statements, increase “Lines between queries” to make each statement easier to scan when reviewing a pull request.
- When in doubt about dialect, start with Standard SQL — it handles the common subset most queries use, and you can switch to a specific dialect only if formatting looks off.
Working with an actual database file instead of a raw query string? Try the online DB viewer to open a SQLite file and run SQL directly in your browser.
Does formatting affect query performance?
No — formatting is purely cosmetic. A query optimizer parses SQL into an execution plan long before whitespace, line breaks, or keyword casing come into play, so a beautifully formatted query and its single-line equivalent run identically and produce the same execution plan. What formatting changes is how quickly a human can read the query, which indirectly improves performance in a different way: well-formatted SQL is easier to review for missing indexes, unnecessary subqueries, or an accidental Cartesian product, all of which do affect real-world speed. In other words, formatting doesn't make a query faster by itself, but it makes the queries that are slow easier to spot.
The same logic applies to minifying. Collapsing a query down to one compact line — useful when embedding SQL in application code, logs, or a configuration file — has zero effect on how the database executes it. Minifying is purely about transport and storage convenience, not execution speed.
Is this SQL formatter safe and private?
Yes. This tool formats every query entirely in your browser using the open-source sql-formatter JavaScript library — nothing you type or upload is ever sent to a server. That makes it safe to paste queries that reference real table names, column names, or business logic you would rather not send to a third party. It also means the tool keeps working offline once the page has loaded, with no rate limits and no account required.
Frequently asked questions
- What does a SQL formatter actually do?
- It rewrites a SQL query's whitespace and casing — indentation, line breaks between clauses, and keyword case — without changing what the query does. The formatted query runs exactly the same as the original.
- Is it safe to format SQL online?
- With this tool, yes — formatting happens entirely in your browser and your query is never uploaded to a server. Be cautious with other online formatters that process SQL server-side, especially for queries containing real schema or business logic.
- Which SQL dialects does this support?
- Standard SQL, MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), and BigQuery. Pick the dialect that matches your database so dialect-specific syntax parses correctly.
- Should SQL keywords be uppercase or lowercase?
- Either is valid — SQL keywords are case-insensitive in every mainstream database. Uppercase is the traditional convention and visually separates keywords from identifiers; lowercase is increasingly common in modern analytics engineering. Consistency matters more than the choice itself.
- What happens if my SQL has a syntax error?
- The formatter shows a plain-language error message and still returns a best-effort formatted result using simple whitespace rules, so you always get something usable. A parse error is often caused by picking the wrong dialect — try switching dialects first.
- Can I format multiple SQL statements at once?
- Yes. Paste or upload a file with multiple semicolon-separated statements and the tool formats all of them, with a configurable number of blank lines between each one.