SQL Formatter
Format and beautify messy SQL queries with proper indentation, keyword casing, and line breaks — or minify them to a single line.
Your SQL never leaves this tab — safe for production queriesBeautify SQL Queries With Proper Indentation and Keyword Casing
About the SQL Formatter
This SQL formatter takes messy, single-line, or inconsistently formatted SQL and turns it into clean, readable code. It places major clauses (SELECT, FROM, WHERE, JOIN) on their own lines, indents sub-clauses, and normalizes keyword casing — all instantly in your browser.
You can choose between uppercase, lowercase, or preserved keyword casing, pick your preferred indent style (2 spaces, 4 spaces, or tabs), and toggle semicolons. The minify mode does the reverse: it strips all unnecessary whitespace to compress your SQL into a single line for embedding or logging.
Privacy matters more for SQL than for most text you might paste into an online tool. A real query carries your schema — table and column names — and often literal values from WHERE clauses: emails, customer IDs, internal codes. Most online formatters send all of that to a server to do the formatting. This one tokenizes and rebuilds the query entirely in your browser, so production SQL never crosses the network. You can load the page, disconnect, and keep formatting.
Why format SQL?
Well-formatted SQL is easier to debug, review, and maintain. A single-line query with 10 JOINs and 15 WHERE conditions is nearly impossible to parse visually. Proper formatting puts each clause on its own line, making the query structure immediately visible.
Before:
select u.id, u.name, o.total from users u inner join orders o on u.id = o.user_id where o.total > 100 and u.active = true group by u.id, u.name order by o.total desc
After:
SELECT
u.id,
u.name,
o.total
FROM users u
INNER JOIN orders o
ON u.id = o.user_id
WHERE
o.total > 100
AND u.active = TRUE
GROUP BY
u.id,
u.name
ORDER BY
o.total DESC;Formatting SQL in editors and the command line
Most SQL editors include a format button, but when you are working outside an IDE — in a terminal, a Slack message, or a Jupyter notebook — this tool is faster than installing a CLI formatter.
# VS Code: Shift+Alt+F (with an SQL extension)
# DBeaver: Ctrl+Shift+F
# DataGrip: Ctrl+Alt+L
# CLI (requires sqlfluff or pg_format):
sqlfluff fix query.sql --dialect postgres
pg_format -s 2 query.sqlFAQ
Is it safe to paste production SQL here?
Yes. The formatter runs entirely in your browser — the query is never sent to a server, logged, or stored. Table names, column names, and the literal values in your WHERE clauses stay on your machine. You can even load the page, go offline, and keep formatting.
What SQL dialects does the formatter support?
The formatter works with standard SQL syntax shared across MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. It recognizes SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, ALTER, JOIN, UNION, CASE/WHEN, and subqueries. Dialect-specific syntax (like MySQL backticks or T-SQL brackets) is preserved as-is.
Does it modify my SQL logic or just the formatting?
It only changes whitespace, line breaks, and keyword casing. Your SQL logic, table names, column names, string literals, comments, and operators are never modified. The formatted query is semantically identical to the original.
What does the minify option do?
Minify collapses your SQL into a single line by removing all unnecessary whitespace and comments. This is useful for embedding SQL in application code, logging, or reducing character count. String literals and identifiers are preserved exactly.