SQL Formatter
Format SQL queries with consistent indentation and readable structure. Copy or download the formatted result without sending data anywhere.
SQL Formatter
This SQL Formatter takes raw, minified, or poorly indented SQL queries and reformats them with proper indentation, keyword alignment, and clean line breaks. It makes complex queries readable by organizing clauses into a clear structure.
The formatting runs entirely in your browser using the sql-formatter library. Your SQL queries never leave your device, making it ideal for formatting stored procedures, complex joins, subqueries, or any SQL that needs cleanup before code review.
How to use
- Paste your raw or minified SQL query into the input editor.
- Click Format SQL to apply indentation and keyword formatting.
- View the formatted query in the output editor with aligned clauses.
- Use Copy for the clipboard, Download for a .sql file, or Clear to reset both editors.
What is SQL formatting?
SQL formatting is the process of reformatting Structured Query Language statements to follow consistent style rules. It places each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) on its own line and adds proper indentation for subqueries and nested conditions.
Well-formatted SQL is essential for debugging query logic, understanding join relationships, and maintaining database code over time. Most database teams enforce SQL formatting standards to ensure consistency across codebases and reduce cognitive load during reviews.
Input notes
The tool accepts SQL queries of any complexity, including SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and other DDL/DML statements. It handles subqueries, CTEs (Common Table Expressions), window functions, and vendor-specific syntax. Keywords are formatted in uppercase by default.
Example
A compressed SQL query becomes readable after formatting:
--- Input (unformatted) ---
SELECT u.name, u.email, 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 ORDER BY order_count DESC;
--- Output (formatted) ---
SELECT
u.name,
u.email,
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
ORDER BY
order_count DESC;