We use cookies and similar technologies to enhance your browsing experience, analyze site traffic, and personalize content and ads. By clicking "Accept", you consent to our use of cookies. Learn more in our Privacy Policy.
by Cosmovex
Format and prettify SQL queries with proper indentation and keyword highlighting. Minify SQL to compress queries. No signup required.
SQL Formatter & Beautifier takes a SQL query written as one long line (or with inconsistent indentation) and rewrites it with predictable line breaks, indentation, and keyword casing so you can actually read it. Paste a SELECT pulled from an ORM log, a stored procedure, or a query someone sent you in chat, and it returns a clean, syntax-highlighted version you can scan in seconds.
It runs entirely in your browser. The query you paste is parsed and reformatted by JavaScript on the page, so nothing is sent to a server and nothing is stored. That matters for SQL specifically, because real queries often contain table names, column names, and sometimes literal values that reveal how a production database is shaped. You can paste a query straight from a log file without worrying about where it ends up. There is no signup, no account, and no upload step.
You paste SQL into the input area and the formatter parses it into its component parts (keywords, identifiers, operators, string and numeric literals, comments), then reassembles it using a consistent layout. The core controls are:
CASE expressions, and parenthesised groups each indent one level deeper.SELECT, FROM, WHERE, JOIN, GROUP BY to uppercase (the common convention) or lowercase. Your identifiers (users, order_id) are left exactly as you typed them.SELECT column lists and IN (...) sets can be broken one item per line.The output is syntax-highlighted so keywords, strings, and comments are visually distinct. Formatting is a pure text transformation: it never changes what the query does, only how it reads. Copy the result with one click.
Here is the kind of single-line query you get out of a query log:
select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.created_at > '2024-01-01' group by u.id, u.email having count(o.id) > 5 order by orders desc;
Formatted with 2-space indent and uppercase keywords, it becomes:
SELECT
u.id,
u.email,
COUNT(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > '2024-01-01'
GROUP BY u.id, u.email
HAVING COUNT(o.id) > 5
ORDER BY orders DESC;
Now the join condition, the filter, and the aggregate logic are each on their own line, so you can review the query clause by clause instead of parsing one wall of text.
JOIN condition or an accidental cartesian product.A formatter rearranges text; it does not understand your database. Keep a few things in mind:
WHERE status = 'select' keeps the lowercase select.SELECT, JOIN, and WHERE are universal, but vendor-specific syntax (PostgreSQL :: casts, MySQL backticks, T-SQL TOP, bracketed [identifiers]) is handled as generic tokens, so it stays intact but may not get bespoke layout.-- line comments and /* block comments */ are kept, though their exact horizontal position can shift.; are each formatted; very large scripts simply take a moment longer.SQL is case-insensitive for keywords: select, SELECT, and SeLeCt all parse identically. So why do most style guides put reserved words in uppercase? It is purely a readability convention. Uppercasing the keywords (SELECT, FROM, WHERE, INNER JOIN) makes the structure of a statement pop out from the data (your table and column names, which stay lowercase or snake_case). When you scan a long query, your eye lands on the clause skeleton first.
This is the same reasoning behind indenting subqueries: the language does not require it, but a human reading the query benefits enormously. The formatter applies the casing rule only to recognised reserved words. It deliberately leaves identifiers untouched, because object names can be case-sensitive depending on the database and quoting ("MyTable" in PostgreSQL is not the same as mytable). Re-casing those could change meaning, so the tool never does it.
All formatting happens in your browser using JavaScript that ships with the page. Your SQL is never transmitted, logged, or stored anywhere. There is no backend that receives the text, so closing the tab is the only cleanup needed.
This is the practical reason to prefer a client-side formatter for SQL over a server-based one. Production queries leak information about your data model: table names hint at your domain, column names reveal what you collect, WHERE clauses sometimes contain real IDs or values, and join structure exposes relationships. Pasting that into a tool that uploads it means handing a stranger a map of your schema. Because this runs locally, you can format a query copied directly from a production log or an incident channel without that risk. You can verify it yourself: format a query, then disconnect from the network and format another. It still works.
No. It only adds line breaks, indentation, and (optionally) keyword casing. The parsed statement is logically identical, so it returns the same rows it did before.
No. Only recognised reserved keywords are re-cased. Identifiers are left exactly as you typed them, because object names can be case-sensitive depending on the database and quoting.
It checks structure, not validity. It cannot know whether a table or column exists, so a query with a typo'd name will still format cleanly. Use it to read SQL, not to verify it.
Universal clauses like SELECT, JOIN, WHERE, GROUP BY, and CASE are handled for any dialect. Vendor-specific syntax such as PostgreSQL casts, MySQL backticks, or T-SQL brackets is preserved as-is, though it may not get dialect-specific layout.
No. Formatting runs entirely in your browser. The SQL you paste is never uploaded, logged, or stored, which is why it is safe to paste a query straight from a production log.
Yes. Statements separated by semicolons are each formatted independently. Large scripts work too; they just take slightly longer to process.
Both line comments (-- ...) and block comments (/* ... */) are kept in the output. Their text is preserved, though their horizontal position may shift to fit the new indentation.
Yes. You can pick 2 spaces, 4 spaces, or a tab per nesting level, so the output matches whatever style your project uses.