The Free SQL Formatter and Beautifier: Format SQL, Pretty Print Long Queries and Minify Them Back to One Line
A query copied out of a log as one endless line. A statement your ORM printed while you chased a bug. Both are readable again in seconds with a good SQL formatter. This guide shows how to format SQL with the free SQL beautifier above, what the SQL pretty print output actually looks like, how to go the other way with the SQL minifier, and, just as usefully, what a formatter can and cannot do for a query that is broken.

1. What a SQL Formatter Does, With a Real Before and After
A SQL formatter re-lays out a query so its structure is visible: clauses on their own lines, conditions indented, keywords in one consistent case. Tables, columns, values and logic stay exactly as you wrote them.
The tool’s sample query, as most people receive it:
select u.id, u.name, count(o.id) as orders, sum(o.total) as revenue from users u left join orders o on o.user_id = u.id where u.created_at >= '2026-01-01' and u.status in ('active','trial') group by u.id, u.name having sum(o.total) > 1000 order by revenue desc limit 50;What Format produces with the default settings:
SELECT u.id,
u.name,
count(o.id) AS orders,
sum(o.total) AS revenue
FROM users u
LEFT JOIN orders o
ON o.user_id = u.id
WHERE u.created_at >= '2026-01-01'
AND u.status IN('active', 'trial')
GROUP BY u.id, u.name
HAVING sum(o.total) > 1000
ORDER BY revenue DESC
LIMIT 50;Each SELECT item gets its own line, so a missing column jumps out. Every major clause and JOIN starts a new line; AND, OR, ON, WHEN, THEN and ELSE are indented; subqueries opening with (SELECT and CASE blocks are indented inside their parent; and statements are separated by a blank line. That is what makes it useful to format SQL with joins and subqueries: the nesting you had to count brackets for becomes something you can see.
2. How to Format a SQL Query in Four Steps
If you are wondering how to format a SQL query without opening an editor or signing up for anything, this is the whole process with the SQL formatter online free tool at the top of the page.
- Paste the query or drop a file. Paste into the SQL box, or drop a .sql or .txt file on the panel above it. A dropped file is read and formatted straight away, which makes this the quickest way to format a SQL file online.
- Pick the keyword case. UPPERCASE keywords is the default; lowercase keywords and Keep as typed are the other two choices.
- Pick the indent. 2 spaces, 4 spaces or Tab, to match the files already in your project.
- Format, then copy or download. Press Format. The Result panel shows the output with a Copy button and a Download button that saves it as query.sql.
The same four steps serve a PostgreSQL query formatter, a MySQL query beautifier for statements lifted from a slow-query log or an admin panel, and a SQLite query formatter for app queries. One general ruleset covers all three, including backtick and square-bracket identifiers, :: casts and $$ bodies; there is no dialect menu.
3. Uppercase or Lowercase Keywords, Tabs or Spaces
The first rule in almost every SQL style guide is keyword case, and teams argue about it more than it deserves. SQL keywords are case-insensitive, as the PostgreSQL documentation on lexical structure states, so the choice is purely about reading. Uppercase makes the skeleton stand out from table and column names; lowercase is quieter.
That is the whole answer to how to uppercase SQL keywords: choose UPPERCASE keywords and press Format. Prefer the other style? Choose lowercase keywords and the tool works as a SQL formatter with lowercase keywords. Keep as typed fixes only the layout. Function names such as count, and your table and column names, always keep the case you gave them.
SQL indentation, tabs or spaces: match the rest of the repository. Need a SQL formatter with a 4 spaces indent? Choose 4 spaces. Settling both choices once lets you beautify SQL for code review: a pull request diff then shows changed logic, not reshuffled whitespace.
4. How to Minify a SQL Query to a Single Line
Sometimes you need the opposite: a query that fits in a string literal, a config value or a log line. That is how to minify a SQL query here: paste it and press Minify instead of Format. It is the quickest way to convert multi-line SQL to a single line, and it also doubles as a way to remove comments from SQL, because both -- and /* */ comments are dropped. The download is named query.min.sql.
This is the sample query after pressing Minify:
select u.id,u.name,count(o.id)as orders,sum(o.total)as revenue from users u left join orders o on o.user_id = u.id where u.created_at >= '2026-01-01' and u.status in('active','trial')group by u.id,u.name having sum(o.total)> 1000 order by revenue desc limit 50;Two things are worth noticing. Minify leaves keywords in the case you typed them, because the Keyword case setting applies to Format only; if you want uppercase keywords on a single line, press Format first, copy the result back into the SQL box, then press Minify. And spaces next to brackets and commas are removed, which is why count(o.id)as orders looks cramped. Databases read that the same way, but if a human will see the line, a formatted copy next to it saves them some squinting.
Two edge cases to know before you minify. Space collapsing also applies inside quoted strings, so a literal like ‘a , b’ becomes ‘a,b’. If a string value depends on its exact spacing, keep the formatted version instead. And # is always read as a MySQL-style comment, so a PostgreSQL query that uses # as an operator will lose the rest of that line. Format keeps comments; Minify does not.
5. Reading an Unreadable One-Line or ORM Query
The classic complaint: a SQL query, unreadable, one line of several hundred characters, usually ORM-generated SQL that is hard to read. Once it is formatted, this checklist finds most problems fast:
- Count the JOIN lines. An unexpected extra join, a common cause of duplicated rows, is easy to spot.
- Read the WHERE block top to bottom. Each AND and OR sits on its own indented line. Check whether an OR needs brackets it does not have.
- Scan the SELECT list. One column per line shows what the ORM actually fetched.
If your editor’s SQL formatter is not working, paste the text here: it lays out whatever it is given rather than rejecting it. It is also a practical SQL formatter for data analysts who want reporting queries tidy before sharing them with colleagues.
6. What It Will Not Do, and Where to Go Instead
Why does a SQL formatter change my query? Here, Format only changes whitespace and keyword case, so results are identical; the two Minify edge cases above are the exceptions. Just as important is what this tool does not attempt:
- It does not validate SQL. It lays out words, strings and symbols; it does not check grammar. A broken query comes out neatly indented and still broken, with no error or line number. Run it against your database to find the fault.
- It does not run, explain or optimise queries or connect to a database.
- It has no dialect selector, syntax highlighting, line-width limit, comma-first style or alias alignment. Commas inside a function call in the SELECT list also start a new line.
- It does not recase table or column names. For that, paste the names into the case converter.
- Comparing two versions of a query? The diff checker shows them side by side.
- Turning INSERT statements into a spreadsheet? The SQL to CSV converter handles INSERT to CSV and back again.
- A JSON column or payload inside the query? Copy the value into the JSON formatter.
- SQL inside Python or Java strings is not unwrapped; copy the query out first. To percent-encode it, the URL encoder does that part.
7. Why Use the Cortexis SQL Formatter
Choosing an online SQL beautifier or a SQL query formatter tool for everyday use? Here is what this one offers.
Free, no account
No sign-up, no email, no daily limit. Paste, press Format and copy.
Format and minify together
Beautify a query for reading or collapse it to one comment-free line for embedding, from the same box, with separate query.sql and query.min.sql downloads.
Your queries stay private
Queries often hold table names, customer IDs or credentials. They are never stored on our servers and nothing is retained after your session.
Never used for training
Your SQL is never used to train any model. A production query stays yours.
Your style, not ours
UPPERCASE, lowercase or keep-as-typed keywords, with 2-space, 4-space or tab indentation, to match your team style guide.
Honest about its limits
It reflows rather than validates, and says so. Where another job needs another tool, this page names it.
It is one of a wider set of free developer and document tools. Testing the pattern behind a LIKE or REGEXP filter? The regex tester shows matches as you type.
8. Frequently Asked Questions (FAQ)
How do I format a SQL query for free?
Paste the query into the SQL box at the top of this page or drop a .sql file on it, choose the keyword case and indent, and press Format. Copy the result or download it as query.sql. There is no account and no daily limit.
Why does a SQL formatter change my query, and does it change the results?
No. Format changes only whitespace and the case of SQL keywords, and SQL keywords are case-insensitive, so the query returns the same results. Table names, column names, function names and string values are left as you typed them.
Will the formatter tell me if my SQL has an error?
No. It lays out the text it is given without checking the grammar, so an invalid query comes out tidy but still invalid. Run the query against your database to see the error and its position.
Can I choose MySQL, PostgreSQL or SQL Server formatting?
There is one general ruleset rather than a dialect menu. It understands backtick, double-quote and square-bracket identifiers, :: casts and $$ bodies, so everyday MySQL, PostgreSQL, SQLite and SQL Server queries format well. Features specific to one dialect are laid out by the same general rules.
How do I convert a multi-line SQL query to a single line?
Paste it and press Minify. Comments are removed and spacing is collapsed, giving one line you can download as query.min.sql. Check string values with meaningful spacing, because spaces inside quotes are collapsed too.
Why did Minify remove part of my PostgreSQL query?
The # character is always treated as the start of a MySQL-style comment, so anything after it on that line is dropped. If your query uses # as a PostgreSQL operator, use the formatted output instead of the minified one.
Is it safe to paste production queries here?
Your SQL is never stored on our servers, nothing is retained after your session, and it is never used for training. That matters when a query contains table names, customer IDs or connection details.
Can it turn INSERT statements into a CSV file?
Not this tool. The SQL to CSV converter turns INSERT statements into CSV rows and CSV back into INSERT statements. Format the query here first if you want to read it before converting.
Working with the data your queries return? Convert exports with the CSV to JSON converter, reshape files with the spreadsheet converter, or sort and de-duplicate ID lists with the line tools. And if you want to write the queries as well as tidy them, our free full-stack web development course and Python development course are a good next step.

