SQL Formatter
Format and beautify SQL queries
SQL Formatter tool
SQL Formatter: key facts
- What it does
- Format and beautify SQL queries
- Category
- Developer Tools
- Cost
- Free, with no account, sign-up, or install.
- Your data
- Runs entirely in your browser — the files and text you enter are never uploaded to a server.
- Last reviewed
- . Report an incorrect result.
About the SQL Formatter
A SQL query crammed onto one line is hard to read and harder to debug. The SQL Formatter reflows it into a clean, indented layout — each major clause on its own line, keywords aligned — so the structure of even a complex query becomes clear at a glance.
Developers and analysts paste queries copied from logs, ORMs, or a colleague to make sense of them, or to tidy a query before committing it. It puts SELECT, FROM, WHERE, JOIN, and other major clauses on their own lines, indents nested parentheses, and can uppercase keywords so they stand out from table and column names. A consistent layout also makes code review kinder: two versions of a tidied query diff far more cleanly than two one-liners.
How to use it
- Paste your SQL query into the input box.
- Set the indent size (1 to 8 spaces) and choose whether to uppercase keywords.
- Click Format.
- Read the reformatted query and copy it back into your editor.
Keyword casing and clause layout
The formatter normalises whitespace, uppercases recognised SQL keywords using word-boundary matching so that a keyword appearing inside an identifier is left alone, then tokenises on whitespace and punctuation to lay clauses out on their own lines.
Uppercase keywords against lowercase identifiers is the long-standing convention, and it earns its keep on a long query: the eye can find the clause boundaries without reading the whole statement. Putting each major clause on its own line does the same for structure, particularly where several joins are involved.
This is a formatter built on pattern matching rather than a full SQL parser, which sets its limits. It is reliable on ordinary statements and will not restructure a deeply nested query into an ideal layout. Dialect-specific syntax and unusual constructs are passed through rather than understood.
- Keywords such as select, from, where, and join are uppercased; column and table names are left as written.
- A single-line query with several joins is broken across lines at the clause boundaries.
- A word matching a keyword inside a longer identifier is not uppercased, because matching is bounded.
Why use this version
- It places major clauses on their own lines and indents nested parentheses, turning a dense one-liner into a readable structure.
- An uppercase-keywords option makes SQL keywords stand out clearly from your tables and columns.
- Indent size is adjustable from one to eight spaces to match your team's style.
- Formatting runs in your browser, so your queries — which can reveal schema details — are never uploaded.
Formatting is cosmetic; these things are not
Formatting changes nothing about how a query executes. If a statement is slow, the answer lies in the execution plan rather than the layout — most engines will show you the plan, and it reveals whether an index is being used, where the row estimates diverge from reality, and which join order was chosen.
A few habits matter more than appearance. Avoid selecting every column when you need three, since the extra transfer and the loss of index-only reads both cost. Understand that a function applied to a column in a predicate usually prevents the index on that column from being used. And prefer explicit joins to comma-separated tables with conditions in the where clause, because the intent of an outer join in particular becomes ambiguous otherwise.
One security point that formatting cannot help with: never assemble a query by concatenating user input, however carefully it appears to be escaped. Parameterised queries are the only reliable defence against injection, and they are also generally faster because the engine can reuse the prepared plan.
Frequently Asked Questions
Does formatting change what my query does?
No. It only changes whitespace, line breaks, and optionally the casing of keywords — the query's logic and results are untouched. Formatting is purely about readability.
Should SQL keywords be uppercase?
It is a common convention because uppercase keywords (SELECT, FROM, WHERE) stand out from lowercase table and column names, making queries easier to scan. It is a style choice, though, so the formatter lets you turn it off.
Does it work with any SQL dialect?
It formats based on common SQL keywords and structure, so it handles standard queries across most databases. Highly dialect-specific syntax may not format perfectly, but the core clauses and indentation will still be applied.
Can it format a minified or single-line query?
Yes — that is exactly its strength. It normalizes the spacing first, then rebuilds the query with each major clause on its own line and proper indentation, turning a dense one-liner back into something readable.