SQL Formatter & Minifier

Beautify or compress SQL across PostgreSQL, MySQL, SQLite, BigQuery, MS SQL, and Standard SQL. Keyword case, indent size, and dialect-aware parsing — all running locally in your browser.

9 dialects · 100% client-side · 0 bytes uploaded

Input SQL

Output

How to Format SQL Online

Paste your SQL query into the Input SQL panel, select a dialect and keyword case, then click Format SQL — or keep Auto-run ON to format as you type. Use Minify to collapse whitespace for embedding in source code or URL parameters. The Swap button lets you round-trip between both modes.

Why dialect matters

SQL is a standard on paper, but every database vendor extends it with its own syntax. Selecting the right dialect ensures the parser recognizes vendor-specific tokens: PostgreSQL's ::type casts and DISTINCT ON, MySQL's backtick identifiers and ON DUPLICATE KEY UPDATE, BigQuery's STRUCT/ARRAY literals, T-SQL's TOP (n) and [bracketed] identifiers, and Oracle's CONNECT BY and WHEN MATCHED. When in doubt, start with Standard SQL and switch to the matching dialect if you see parse errors.

Format vs Minify

Format (pretty-print) adds line breaks and indentation to make queries auditable — ideal for code reviews, migrations, and documentation. Minify collapses the query to a single compact line, suitable for embedding in application code, log lines, or URL parameters. Single-line -- comments are stripped during minification because they would comment out everything that follows in one-line SQL.

Privacy

Nothing is uploaded. The parser and formatter run entirely in your browser using the open-source sql-formatter library. Production queries, schema names, and hardcoded values stay on your machine — safe to use with sensitive SQL you'd never paste into a cloud service.

Frequently Asked Questions

Will formatting change the meaning of my query?

No. Formatting only rewrites whitespace, indentation, and optionally keyword case. The logical query — tables, columns, predicates, joins, subqueries — is preserved exactly. String literals and comments are also left untouched.

Why does my query fail to format?

The parser needs syntactically valid SQL. Common causes: unclosed quotes or parentheses, a dialect mismatch (e.g. formatting MySQL backticks under Standard SQL), or mid-statement templating placeholders like {{var}}. Try switching dialects, or strip templating tokens before formatting.

Does minify remove comments?

Minify collapses whitespace and newlines. Single-line -- comments become problematic in one-line SQL because they comment out everything after them on the same line, so they are stripped. Block comments /* … */ are generally preserved but may be removed depending on placement. Review the output before pasting into code.

Can I format a file with multiple statements?

Yes. Separate statements with semicolons and each will be formatted independently. This works well for migration scripts, seed files, and multi-statement stored procedure bodies.

Should keywords be uppercase or lowercase?

It is a style preference. Uppercase keywords (SELECT, FROM, WHERE) are the traditional convention and make queries easier to scan because keywords stand out from identifiers. Lowercase is growing in popularity in modern codebases. Pick one and apply it consistently across your project.

Related Tools