SQL Formatter
A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call
Free SQL formatter. Paste a query to beautify it with one clause per line, indented columns and subqueries, and keyword case, or minify it. Nothing is uploaded.
Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.
How to use the SQL formatter
- Paste your SQL into the box. It can be one query or several statements separated by semicolons.
- Choose Beautify or Minify.
- Choose how keywords should look: UPPERCASE, lowercase, or kept as you typed them.
- Choose the indent: 2 spaces, 4 spaces or tabs.
- Copy the result with the Copy button.
The SQL formatter works entirely in your browser. Your queries are never uploaded, which matters when they contain table names, customer data or business logic you'd rather keep private.
What the SQL formatter does
When you beautify a query, the SQL formatter:
- Puts each main clause on its own line: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, and others such as INSERT INTO, VALUES, UPDATE, SET and WITH.
- Indents the contents of each clause, with one column or expression per line in SELECT lists.
- Starts each AND and OR condition on a new line, so long WHERE clauses are easy to scan. Conditions inside BETWEEN … AND stay together.
- Indents joins under FROM, keeping each JOIN with its ON condition.
- Nests subqueries, indenting a SELECT inside brackets one level deeper than the clause around it.
- Spaces operators consistently, so x=1 becomes x = 1.
- Changes keyword case if you choose, without touching table names, column names, strings or comments.
When you minify, it removes comments, line breaks and extra spaces, putting the whole query on a single line.
An example
This query is hard to read on one line:
select o.id, c.name, sum(o.total) as revenue from orders o left join customers c on c.id = o.customer_id where o.status = 'paid' and o.created_at >= '2026-01-01' group by o.id, c.name having sum(o.total) > 100 order by revenue desc limit 20;
The SQL formatter turns it into:
SELECT
o.id,
c.name,
SUM(o.total) AS revenue
FROM
orders o
LEFT JOIN customers c ON c.id = o.customer_id
WHERE
o.status = 'paid'
AND o.created_at >= '2026-01-01'
GROUP BY
o.id,
c.name
HAVING
SUM(o.total) > 100
ORDER BY
revenue DESC
LIMIT
20;
Each part of the query is now easy to find, and you can see at a glance which columns are selected, how the tables are joined and how the results are filtered.
Why format SQL?
- Readability: formatted SQL is much easier to read, review and debug, especially for long queries with many joins and conditions.
- Code reviews: consistent formatting makes changes stand out in version control diffs, so reviewers see what actually changed.
- Finding mistakes: putting each condition on its own line makes it easier to spot a missing AND, a wrong comparison or a misplaced bracket.
- Team standards: a consistent style means everyone on the team reads queries the same way.
- Documentation: formatted queries are clearer in reports, wikis and tutorials.
Keyword case
SQL keywords aren't case-sensitive in most databases, so SELECT, select and Select all work the same. Many teams write keywords in uppercase to make them stand out from table and column names, which is the default in the SQL formatter. Others prefer lowercase for a cleaner look. Pick one and use it consistently. Note that table and column names can be case-sensitive in some databases, depending on how they were created and quoted, which is why the SQL formatter never changes identifiers.
What the SQL formatter leaves alone
Formatting should never change what a query does. The SQL formatter:
- Doesn't change strings, including text inside single quotes, such as 'O''Brien'.
- Doesn't change quoted identifiers in double quotes, backticks or square brackets.
- Keeps comments when beautifying (they're removed only when you minify).
- Doesn't reorder anything or rewrite expressions.
It's a formatter, not a validator, so it won't tell you whether a query is correct. If the brackets don't balance, it shows a warning.
Minifying SQL
Minified SQL is useful when you need to embed a query in a single line, such as in a configuration file, a URL parameter, a log message or code that builds queries as strings. Because minifying removes comments, keep the formatted version in your source files and minify only where needed. Note that -- comments end at a line break, which is why they must be removed before putting a query on one line.
Dialects
SQL has a common core, but each database adds its own features: PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery, Snowflake and others all have their own syntax. The SQL formatter handles the common clauses, joins, subqueries, CASE expressions and standard functions that appear in most dialects. For very dialect-specific syntax, such as procedural code inside stored procedures, it formats what it recognises and leaves the rest readable.
Who uses a SQL formatter
Developers use it to tidy queries before committing them or sharing them with colleagues. Data analysts use it to read queries generated by BI tools, which are often one very long line. Database administrators use it when reviewing slow queries from logs, and students use it to learn SQL structure.
Need more customers from Google?
This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit manages Google Ads for small and mid-size businesses, and only Google Ads. We check your account before we ever get on a call, then fix the structure, the keywords, the tracking and the ads, with month-to-month terms and no long contract. Book a free audit call.
Common SQL style conventions
- One clause per line, with the contents indented.
- Uppercase keywords, lowercase or snake_case identifiers.
- Leading or trailing commas: the SQL formatter uses trailing commas, the more common style; some teams prefer leading commas because they make it easy to comment out a line.
- Meaningful aliases, such as customers c or orders o, used consistently.
- Explicit JOIN syntax rather than listing tables separated by commas in FROM.
Other formatters
For other formats, the JSON formatter and XML formatter tidy data files, the CSS minifier shrinks stylesheets, and the XML to JSON converter turns XML into JSON.
Common mistakes
- Pasting queries with sensitive data into online tools that upload them. This SQL formatter runs in your browser and doesn't upload anything.
- Minifying source files, which removes comments you may need later.
- Assuming formatting checks correctness. Test queries against your database.
Formatting queries from logs and tools
Queries copied from application logs, ORMs, BI dashboards and query monitors often arrive as one enormous line, sometimes thousands of characters long. Pasting them into the SQL formatter is usually the quickest way to understand what they do. Once formatted, look first at the FROM and JOIN lines to see which tables are involved, then at the WHERE clause to see how rows are filtered. Long queries generated by tools often repeat the same expression many times, which formatting makes much easier to spot.
Formatting CTEs
Common table expressions, written with WITH, let you break a complex query into named steps. The SQL formatter puts WITH on its own line and nests each CTE's SELECT inside its brackets, so each step reads like a small query of its own. Naming CTEs clearly, such as paid_orders or monthly_totals, and formatting them consistently, makes complex analysis queries much easier to review and maintain.
CASE expressions
CASE expressions are kept on one line by the SQL formatter, so short conditions stay compact, for example CASE WHEN a > 1 THEN 'x' ELSE 'y' END AS k. Commas and AND conditions inside a CASE don't start new lines, which keeps the expression together as a single column in the SELECT list. For very long CASE expressions, you may prefer to add your own line breaks after formatting.
Using the SQL formatter in a team
If your team doesn't use an automatic formatter in its editor or build pipeline, agreeing on a few simple rules, and running queries through the SQL formatter before sharing them, gives most of the benefit. Automatic formatting in your editor or as a pre-commit check is even better for large codebases, because it keeps every file consistent without anyone having to think about it.
Formatting before you share
Before pasting a query into a ticket, chat or document, run it through the SQL formatter so colleagues can read it at a glance.
Sources and further reading
- SQL on Wikipedia: history, syntax and standards.
- PostgreSQL documentation: SQL syntax, a thorough reference on how SQL is structured.
- Simon Holywell: SQL style guide, a widely used set of formatting conventions.
Frequently asked questions
How do I format a SQL query?
Paste it into the SQL formatter and choose Beautify. Each clause goes on its own line with the contents indented.
Does formatting change how my query runs?
No. It only changes spaces, line breaks and keyword case.
Is my SQL uploaded anywhere?
No. The SQL formatter runs entirely in your browser.
Should SQL keywords be uppercase?
It's a common convention, but not required. Choose a style and use it consistently.
Can it minify SQL?
Yes. Choose Minify to put the query on one line and remove comments.
Is the SQL formatter free?
Yes. It's free, needs no sign-up, and works in your browser.
Free PPC audit
See where your ad budget leaks.
We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.