SQL Formatter & Beautifier
Format and minify SQL queries locally inside your browser with UPPERCASE/lowercase/Keep keyword casing, 2-space/4-space/Tab indentation, SELECT column wrapping, and .sql download while safeguarding quoted strings and comments.
How to Use SQL Formatter & Beautifier
Paste raw or compressed SQL (or load Sample Query)
Enter single-line SELECT, JOIN, INSERT, UPDATE, DELETE, or UNION SQL statements into Raw SQL Query.
Choose Keyword Case & Indentation
Select UPPERCASE, lowercase, or Keep Original keywords and pick 2 Spaces, 4 Spaces, or Tab indent.
Click Format SQL / Minify SQL, Copy, or download .sql
Compare indented clauses on the right, compact into one line via Minify SQL if needed, or save formatted-query.sql.
Practical Use Cases
- Expand single-line PostgreSQL, MySQL, or SQLite ORM/application log queries into clean indented clauses during debugging.
- Standardize SQL keyword casing (UPPERCASE or lowercase) across team migration scripts or PR reviews.
- Wrap dense 10-column SELECT projections cleanly onto individual indented lines while keeping functions like COUNT(o.id) intact.
- Compact documented queries into clean single-line strings via Minify SQL (stripping -- and /* */ comments).
Real Input & Output Examples
Formatting a Compressed Multi-Table JOIN Query
Preserves quoted 'active' and date literals while aligning SELECT columns, JOIN, WHERE, and ORDER BY.
select u.id, u.email, count(o.id) as orders from users u inner join orders o on u.id = o.user_id where u.status = 'active' group by u.id order by orders desc limit 25;
SELECT u.id, u.email, COUNT(o.id) AS orders FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE u.status = 'active' GROUP BY u.id ORDER BY orders DESC LIMIT 25;
Minifying Formatted SQL For Single-Line Strings
Minify SQL strips -- comments and collapses whitespace cleanly.
SELECT id, email -- internal filter FROM users WHERE status = 'active';
SELECT id, email FROM users WHERE status = 'active';
Features, Supported Standards & Limitations
String & Comment Placeholder Tokenizer
Locks single-quoted strings ('...'), double-quoted identifiers ("..."), backtick identifiers (`...`), and -- / /* */ comments with safe callback restoration so text inside quotes (even '$100') is never altered.
Major Clause & Sub-Condition Breaking
Breaks before SELECT, FROM, JOIN variants, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, UNION, and indents ON/AND/OR lines.
Parenthesis-Aware SELECT Column Splitting
Tracks parenthesis depth when splitting SELECT column lists so commas inside aggregate functions like COALESCE(a, b) don't wrap mid-argument.
Minify Mode + .sql Export
Offers instant whitespace/comment compaction alongside Clipboard Copy and formatted-query.sql file download.
Supported Formats, Standards & Inputs
- Standard ANSI SQL, PostgreSQL, MySQL/MariaDB, SQLite & SQL Server SELECT/JOIN/DML queries
- Single/double/backtick SQL quoting plus -- line and /* */ block comments
- 2 Spaces, 4 Spaces, or Tab indentation + .sql download
Limitations & Compatibility
- Uses a fast tokenizer/clause-breaker suited for SELECT, JOIN, INSERT, UPDATE, DELETE, and UNION queries rather than a dialect-specific full SQL AST compiler—nested subqueries inside parentheses, complex CTEs (WITH ... AS), and vendor stored procedures (PL/pgSQL / T-SQL BEGIN...END) format cleanly only at top-level clauses.
- Case transformation targets its built-in SQL keyword set (such as SELECT, WHERE, JOIN, COUNT, SUM, CASE) so vendor-specific function names not in the core keyword list keep their original casing.
Related Workflow Tools
Complementary utilities commonly paired with SQL Formatter & Beautifier
JSON Formatter
Prettify (2/4 spaces) and minify JSON locally with syntax error alerts.
UUID Generator
Generate 1–100 Version 4 UUIDs locally via Web Crypto API.
JavaScript Minifier
Compact JS safely in-browser while preserving quoted strings & URLs.
Regex Tester & Debugger
Test JS RegExp patterns, flags, capture groups & replacements live.
Frequently Asked Questions
Will converting keywords to UPPERCASE change string words like 'select' inside quotes?
No—before formatting keywords or breaking lines, the formatter tokenizes all single-quoted strings, double-quoted identifiers, backticks, and SQL comments so quoted text remains untouched.
How does SQL Formatter handle nested function commas like COUNT(a, b) or COALESCE(x, 'N/A')?
The SELECT list splitter tracks open '(' and closing ')' nesting depth, splitting commas onto new lines only at depth 0.
Does Minify SQL delete comments?
Yes—clicking Minify SQL intentionally removes -- and /* */ SQL comments and collapses whitespace for compact production query strings.
Which SQL dialects work best?
Standard ANSI SQL, PostgreSQL, MySQL, MariaDB, SQLite, and SQL Server SELECT/JOIN/INSERT/UPDATE/DELETE queries format cleanly.
Does SQL Formatter execute queries or send database schemas anywhere?
Never—all formatting happens purely client-side inside your browser with zero database connections.