Examples
Format a joined aggregate query
select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=true group by u.id,u.name order by orders desc;SELECT
u.id,
u.name,
COUNT(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = TRUE
GROUP BY
u.id,
u.name
ORDER BY
orders DESC;With the default Standard SQL configuration, keywords and functions are uppercased and clauses are wrapped with two-space indentation.
Minify SQL and strip comments
SELECT id, name -- visible columns
FROM users /* active accounts */
WHERE active = true;SELECT id, name FROM users WHERE active = true;The minifier removes line and block comments and collapses whitespace without running the dialect formatter.
About this tool
The SQL Formatter turns cramped, one-line or inconsistently-styled SQL into clean, readable queries. It is powered by the battle-tested sql-formatter engine and understands 11 dialects — Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Redshift, Spark SQL and Snowflake — so keywords, functions, data types and identifier quoting are handled the way your database expects.
Unlike a one-size-fits-all beautifier, every stylistic choice is yours: force keywords, data types, functions and identifiers to uppercase, lowercase or preserve them; pick the indent width or use tabs; switch between standard and tabular indentation; place AND/OR at the start or end of lines; and tune the expression width that controls when long clauses wrap. Turn on auto-format to reformat as you type, or use Minify to collapse a query onto a single line.
Everything runs locally in your browser — no query is ever uploaded, so it's safe for production SQL. Need to review a change instead of tidy one query? Switch to the Compare tab to diff two queries side by side.
How to use
Paste and format
Paste SQL into the Input pane. With Auto-format on it reformats instantly; otherwise click Format. The result is syntax-highlighted in the Output pane.
Match your database dialect
Choose the dialect (e.g. PostgreSQL or BigQuery) so dialect-specific keywords and quoting format correctly.
Tune the style
Set keyword/identifier casing, indent width, tabular indentation and logical-operator placement until the output matches your team's style guide.
Copy, download or minify
Copy the formatted SQL, download it as a .sql file, or click Minify to collapse it to a single line for embedding in code.
Use cases
Normalizing SQL in code review
Format a query with the team's dialect and casing rules so reviewers can focus on logic rather than layout.
Cleaning generated SQL
Turn compressed ORM or log output into a readable statement for debugging and query-plan analysis.
Preparing an embeddable statement
Minify a reviewed query when a single-line form is more convenient for fixtures, scripts or configuration.
Standardizing migration files
Apply consistent indentation, clause wrapping and keyword casing before committing database changes.
Key formatting options
| Option | What it does |
|---|---|
| Dialect | Parse rules for 11 databases (PostgreSQL, MySQL, T-SQL, BigQuery, …) |
| Keyword / type / function / identifier case | Force UPPERCASE, lowercase or preserve — independently |
| Indent width & tabs | Spaces per level, or use tab characters |
| Indent style | Standard, or tabular (aligned) left/right |
| Logical operator newline | Put AND/OR before (line start) or after (line end) |
| Expression width | Column budget before long expressions wrap |
| Minify | Collapse to one line, stripping comments and extra whitespace |
All processing is client-side — your SQL never leaves the browser.
Common mistakes
Mistake:Formatting with the wrong SQL dialect.
Fix:Select the target database first so dialect-specific syntax and quoting are parsed correctly.
Mistake:Treating successful formatting as proof that a query is safe or correct.
Fix:Run the statement against the intended database, inspect parameters and permissions, and review its execution plan separately.
Mistake:Using Minify on SQL whose comments carry required hints or operational context.
Fix:Review comments before minifying; the minifier deliberately removes both line and block comments.
Mistake:Expecting the minifier to be a complete dialect-aware lexer.
Fix:Use it for ordinary quoted SQL; verify statements that rely on dialect-specific quoting, dollar strings or unusual comment syntax.
Frequently asked questions
Related guides
From Spreadsheet Rows to SQL INSERT Statements
How to turn a CSV export into typed, quoted, and safe SQL INSERT statements — and why the naive string-concatenation approach breaks on quotes, NULLs, and dates.
Build SELECT Queries Without Syntax Errors
The canonical clause order — SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT — and the most common mistakes when typing SQL by hand, from unescaped quotes to forgotten GROUP BY columns.
How to Build a SELECT Query Visually: A SQL Builder Guide
Compose a SELECT query by stacking clause blocks instead of typing SQL. Learn JOIN, WHERE, GROUP BY and ORDER BY by building them, and see how the builder keeps clauses in canonical order automatically.
How to Format SQL: A Complete Guide to Clean Queries
Turn messy, one-line SQL into readable queries. A practical guide to dialects, keyword casing, indentation, logical-operator placement, minifying, and every option in the SQL Formatter.
References & standards
Related tools
Base64 Toolbox
Professional Base64 workspace for text, files and images with Base64URL, MIME, Data URI, strict validation, image preview and ready-to-use snippets.
CSV to Chart
Paste or upload CSV data and generate bar, line, pie, or doughnut charts. Export as PNG.
CSV to JSON Converter
Paste CSV data and convert it to pretty-printed JSON instantly — supports custom delimiters, header row toggling, and value trimming.
CSV to Markdown Converter
Convert CSV to a Markdown table and Markdown tables back to CSV
CSV to SQL Converter
Generate SQL INSERT statements from CSV data
cURL to Code Converter
Convert cURL commands to code snippets in multiple languages. Parse cURL and generate JavaScript, Python, PHP, and more.