SQL Formatter & Beautifier
Format, minify, and validate SQL queries with syntax highlighting — all in your browser, nothing sent to any server
Formatted SQL will appear here.
What Is a SQL Formatter?
A SQL formatter — also called a SQL beautifier, SQL pretty printer, or SQL indenter — takes a SQL query written on a single line or with inconsistent spacing and reformats it with clean, readable indentation, proper line breaks, and consistent keyword casing. Whether you received a minified query from an ORM, copied SQL from a database client, or wrote a query quickly without regard for style, a SQL formatter makes it immediately readable.
This tool supports:
- 2-space or 4-space indentation — match your project’s coding standard
- UPPERCASE or lowercase keywords — follow the convention your team prefers
- Multiple statements — format entire SQL scripts with multiple queries separated by semicolons
SQL Beautifier vs SQL Minifier
These are opposite operations serving different purposes:
SQL beautifier (the Format button) expands compact SQL with newlines, indentation, and consistent keyword casing. It makes queries easy to read, review, and debug. Use it during development, code review, and documentation.
SQL minifier (the Minify button) strips all unnecessary whitespace and comments, producing the most compact valid SQL string. This is useful for embedding queries in source code strings, reducing log file verbosity, or storing queries compactly in configuration.
Example — the same query before and after formatting:
select u.id,u.name,count(o.id) as order_count from users u left join orders o on u.id=o.user_id where u.active=1 group by u.id,u.name order by order_count desc limit 10
After formatting with 2-space indentation and uppercase keywords:
SELECT u.id, u.name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE u.active = 1
GROUP BY u.id, u.name
ORDER BY order_count DESC
LIMIT 10
Supported SQL Syntax
This formatter understands a broad range of standard SQL syntax:
Data Query Language (DQL):
SELECTwith column lists, aliases (AS),DISTINCTFROMwith table aliasesJOINvariants:INNER JOIN,LEFT JOIN,RIGHT JOIN,FULL OUTER JOIN,CROSS JOIN,NATURAL JOINWHEREwithAND,OR,NOT,IN,EXISTS,BETWEEN,LIKE,IS NULLGROUP BY,HAVINGORDER BYwithASC/DESCLIMITandOFFSET- Subqueries in
SELECT,FROM, andWHEREclauses UNION,INTERSECT,EXCEPTCASE WHEN … THEN … ELSE … ENDexpressions- Common Table Expressions (CTEs) with
WITH
Data Manipulation Language (DML):
INSERT INTO … VALUES …UPDATE … SET …DELETE FROM …
Data Definition Language (DDL):
CREATE TABLEALTER TABLEDROP TABLE
Aggregate and Window Functions:
COUNT,SUM,AVG,MIN,MAXRANK,DENSE_RANK,ROW_NUMBER,NTILE,LAG,LEADFIRST_VALUE,LAST_VALUE
SQL Validation
The built-in validator performs lightweight structural checks before formatting:
| Check | What It Detects |
|---|---|
| Parenthesis balance | Unmatched ( or ) |
| Unclosed strings | Single or double quotes that are never closed |
| Unclosed block comments | /* without a matching */ |
Unexpected ) | Closing paren without an opening paren |
These checks catch the most common SQL syntax errors that would prevent a query from running. Note that the validator does not execute the query or connect to a database — it performs static analysis only.
SQL Syntax Highlighting
The output panel applies color-coded syntax highlighting to make queries easier to read:
| Token type | Color | Examples |
|---|---|---|
| Keywords | Blue | SELECT, FROM, WHERE, JOIN |
| Functions | Purple | COUNT, SUM, COALESCE, ROW_NUMBER |
| Strings | Green | 'active', "users" |
| Numbers | Orange | 42, 3.14, 0xFF |
| Comments | Gray (italic) | -- comment, /* block */ |
| Operators | Red | =, <>, >=, ` |
Common Use Cases
Query review: Format a query written by a colleague or generated by an ORM before reviewing it in a pull request. Consistent formatting makes logical structure immediately visible.
Debugging: When a query returns unexpected results, formatting it first reveals the logical structure — which WHERE conditions apply to which JOIN, whether a subquery is in the right place, and how AND/OR conditions are grouped.
Learning SQL: Formatted, well-indented SQL shows the structure of complex queries — subqueries, joins, case expressions — in a way that raw minified SQL does not.
Documentation: Format queries before copying them into README files, wikis, or internal documentation so readers can understand the structure at a glance.
Code embedding: Minify queries before embedding them as string literals in application code, reducing visual noise and keeping code files cleaner.
SQL Formatting Best Practices
- Always uppercase SQL keywords:
SELECT,FROM,WHERE,JOIN, etc. This visually distinguishes language syntax from user data (table names, column names, values). - One clause per line: Start
SELECT,FROM,WHERE,GROUP BY,ORDER BY,HAVING,LIMITon new lines to make query structure immediately scannable. - Indent subqueries: A subquery inside a
FROMorWHEREclause should be indented relative to the outer query. - Align
JOINconditions: PutONon the same line as theJOINkeyword, keeping the relationship between tables explicit. - Comma placement: Leading commas (at the start of each column line) make it easier to comment out a column without editing the previous line; trailing commas (at the end) are more natural to read.
Frequently Asked Questions
Does this formatter support MySQL, PostgreSQL, SQL Server, and Oracle?
The formatter handles standard SQL syntax that is common across all major databases. Dialect-specific syntax (MySQL’s STRAIGHT_JOIN, PostgreSQL’s RETURNING, SQL Server’s TOP, Oracle’s ROWNUM) may be preserved as identifiers but may not be formatted perfectly. Core DQL/DML/DDL syntax works across all dialects.
Can I format stored procedures or PL/SQL? The formatter is designed for standard SQL queries. Procedural SQL extensions like PL/SQL (Oracle), T-SQL blocks (SQL Server), or PL/pgSQL (PostgreSQL) may not format correctly, as they include language constructs (variables, loops, conditionals) beyond standard SQL.
What happens to my SQL comments?
Line comments (-- comment) and block comments (/* comment */) are preserved in formatted output. In minified output, comments are removed.
Is there a size limit for SQL input? The formatter runs entirely in your browser. It handles queries well over 100KB without noticeable delay. For extremely large SQL scripts (thousands of queries), consider splitting them into smaller batches.
Is my SQL query sent to a server? No. All formatting, minification, and validation runs entirely in your browser using JavaScript. No SQL query or data is transmitted anywhere. Your queries never leave your device.