Format and highlight SQL queries online. Auto-align SELECT, JOIN, WHERE, and subqueries
A tool for formatting and minifying SQL queries.
Formatting adds line breaks and indentation for SQL keywords: SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, and others.
Nested parentheses automatically receive an additional indentation level.
Minification removes all extra whitespace and comments, compressing the query into a single line.
All major SQL dialects are supported: MySQL, PostgreSQL, SQLite, SQL Server.
SQL Formatter and Minifier Online
A free online tool for formatting and minifying SQL queries. Paste your query, choose an indentation style — and get a readable, neatly formatted code or a compact single-line version.
Why format SQL
SQL queries generated by ORMs, copied from logs, or written in a hurry are often a single long line without indentation. Such code is hard to read, debug, and maintain. The SQL formatter transforms an unreadable query into structured text with logical line breaks and indentation.
Well-formatted SQL is not just aesthetics. It is the ability to quickly find an error in a WHERE clause, spot a redundant JOIN, or understand the grouping order. For team code reviews, formatting is mandatory.
How the formatter works
The tool analyzes the SQL query by tokens: it recognizes keywords, string literals, parentheses, commas, and semicolons. String literals in single quotes, double quotes, and backticks are handled separately — their content is not modified.
Formatting algorithm:
- Tokenization preserving string literals
- Whitespace normalization in non-string parts
- Line breaks before top-level keywords
- Indent increase on open paren, decrease on close paren
- Sub-keyword indentation (AND, OR, ON)
SQL keywords
| Group | Keywords | Behavior |
|---|---|---|
| Primary operators | SELECT, FROM, WHERE, HAVING, LIMIT | New line, no indent |
| JOIN operators | JOIN, LEFT JOIN, RIGHT JOIN, INNER JOIN | New line, no indent |
| Grouping/sorting | GROUP BY, ORDER BY | New line, no indent |
| Sub-keywords | AND, OR, ON, WHEN, THEN, ELSE | New line, 2-space indent |
| Subqueries | ( ... ) | Increase indent level |
| Enumerations | , (comma) | New line continuation |
Query minification
Minification is the reverse task: remove all extra whitespace, line breaks, and comments, compressing the query into a single line. Useful for:
- Passing SQL via HTTP requests or query strings
- Storing queries in configuration files
- Comparing queries during performance A/B testing
- Generating queries in code without extra line breaks
The tool correctly handles string literals during minification — spaces inside strings are not removed.
Supported dialects
The formatter works with the syntax of all major DBMS:
- MySQL / MariaDB — backticks for identifier quoting:
`table_name` - PostgreSQL — double quotes:
"column_name" - SQLite — compatible with MySQL and PostgreSQL syntax
- SQL Server (T-SQL) — square brackets not supported, use double quotes
- Oracle SQL — basic syntax is supported
FAQ
Does the formatter change query logic? No. It only changes whitespace and keyword casing. Logic, values, and operation order remain unchanged.
Can I format multiple queries at once? Yes — paste multiple queries separated by semicolons. Each ; starts a new formatted query on a new line.
What about stored procedures? The formatter targets DML/DDL queries. Complex procedures with BEGIN/END may not format perfectly.
See also: JSON Formatter · Diff (text compare) · JS Minifier · CSS Minifier
Useful articles
WCAG Color Contrast: Website Accessibility Guide
A complete guide to color contrast: WCAG 2.1 standards, AA and AAA levels, calculation formula, practical examples of good and bad contrast, and how to fix accessibility issues.
CSS Border Radius: Rounding Element Corners
How to use border-radius: syntax, shorthand notation, elliptical corners. Online border-radius generator.