Format SQL instantly
Paste SQL, choose dialect, keyword case, and indentation style, then copy the formatted output

SELECT field1, field2, field3 FROM my_table WHERE my_condition;
The SQL Prettify and Format tool takes messy SQL and produces a clean, consistent layout. It helps you spot mistakes faster, review changes in pull requests, and keep queries readable across a team.
Everything runs locally in your browser: paste SQL, choose options, copy the formatted query.
Who is this for?
If you also work with JSON and URLs, you may like our JSON prettify and format and URL encoder for quickly cleaning inputs during debugging.
Quick sanity check (with a tiny “math” example)
Many formatting styles use a fixed indentation width (often spaces). If your query has nested blocks, the visual indent is roughly “levels times width”.
If you see indentation that looks “too deep”, try a different indent style, or reduce nesting (for example, by extracting a subquery into a CTE).
Example 1: Fix a one-line query
Input (messy):
select a,b,c from orders where created_at>='2026-01-01' and status in ('paid','shipped') order by created_at desc;Suggested options: Dialect “Standard SQL”, Keyword case “UPPERCASE”, Indent style “Standard”.
Result: the formatter places each clause (SELECT, FROM, WHERE, ORDER BY) on clean lines, so reviewing logic becomes easier.
Example 2: Make indentation consistent in a nested query
You paste a query with uneven spacing and mixed casing.
Use “Tabular left” if you want aligned columns, or “Standard” if you care more about compact readability. A helpful mental model is that indentation accumulates by nesting level.
If your expected nesting level is and your style uses , the visible indentation is about spaces.
Use case: safer code reviews
Background: reviewers miss logic changes when whitespace is inconsistent.
Input: a query with nested conditions and joins (dialect PostgreSQL).
Result: formatted output reduces “diff noise”. If you indent by spaces and the maximum nesting is , the deepest blocks line up at about spaces.
How to apply: format before committing or pasting into a PR comment.
Use case: BI dashboards and saved queries
Background: dashboards are maintained for months (or years).
Input: BigQuery SQL copied from an ad-hoc notebook.
Result: consistent keywords and indentation make it easier for someone else to pick up later.
How to apply: format before saving, then store the formatted SQL alongside a short description.
Use case: sharing reproducible inputs
Background: you want to send a colleague the exact query + settings.
Input: SQL + your chosen options (dialect, keyword case, indent style).
Result: a shareable URL. (If the SQL is very large, sharing without results is usually better.)
How to apply: use Share, then decide whether to include results.
Tip: if you need to share SQL in an environment that only accepts a single line, you can pair this tool with our URL encoder or Base64 string encoder/decoder depending on your workflow.
Before a PR or code review
Useful: reduces noisy diffs and clarifies intent.
Not ideal: if your project enforces a different SQL style guide.
Cleaning dashboard queries
Useful: consistent formatting makes long-term maintenance easier.
Not ideal: if the BI tool rewrites SQL on save anyway.
Debugging a failing query
Useful: makes joins/filters visually separable.
Not ideal: if the query is not valid SQL yet (fragments).
Standardizing team style
Useful: choose a consistent keyword case across a codebase.
Not ideal: if you need highly customized formatting rules.
Sharing SQL in chat or tickets
Useful: formatted SQL is easier to skim and quote.
Not ideal: if the platform collapses whitespace aggressively.
When it might not fit
Useful: quick readability.
Not ideal: vendor-specific syntax not covered by the selected dialect.
Practical tips
A SQL formatter is a deterministic transformer: it reads your input string and returns a new string with normalized whitespace, line breaks, and keyword casing.
What the symbols mean
If you want a quick way to reason about indentation depth, you can think in terms of indentation width and nesting level :
What is a “dialect”?
SQL is a family of languages. Most databases share common syntax, but details differ (functions, quoting rules, LIMIT/OFFSET behavior, and more). Selecting the right dialect helps the formatter interpret tokens more accurately.
Keyword case
Keyword case affects readability. Some teams prefer for SQL keywords, while others prefer a lighter look. “Preserve” is useful when you’re formatting someone else’s query and want minimal semantic changes.
Tabular indentation
Tabular styles try to align columns and aliases to create a “table-like” look. It can be great for SELECT lists, but may look wide on small screens.
Dialects change token rules and functions. If formatting looks odd, switch the dialect to match your target database first.
Formatting is intended to change whitespace and casing only. Still, you should treat the formatted output as code: run it in a safe environment and verify results.
Most formatters expect syntactically valid SQL. If you have fragments, try adding missing parts temporarily (for example, a placeholder table name) to get a clean layout.
Prefer sharing without results, and remove secrets, customer identifiers, or internal table names whenever possible.
No. It’s a formatter, not a validator, query planner, or security scanner.
Limitations / disclaimers
This tool helps with readability, but it does not guarantee query correctness, performance, or compliance. Always test important queries and follow your organization’s data handling policies.
External references / sources
Edit rich text in a simple WYSIWYG editor and copy Prettier-formatted HTML instantly. Runs locally in your browser.
Parse, validate, and format phone numbers. Get the country, calling code, type, and common formats like E.164 and RFC3966. Runs locally in your browser.
Encode and decode URL-formatted strings (percent-encoding). Runs locally in your browser with instant copy.
Parse a URL into its constituent parts (protocol, username, password, hostname, port, path, params). Runs locally in your browser with instant copy.
Convert fractions to percentages and vice versa instantly
Convert grams to tablespoons for any ingredient instantly. Perfect for cooking and baking with support for multiple ingredients.