⚙️ Settings
SQL Formatter — Beautify and Minify SQL Queries Online
The SQL Formatter takes a messy, unindented SQL query and beautifies it with proper line breaks and indentation, or does the reverse — minifying a readable query down to a single line. It's built for developers, analysts, and QA engineers who need to format SQL query online before a code review, or minify SQL to one line for embedding in application code or a config file. Paste your query, pick a mode, and get a clean result instantly.
⚡ Key Takeaways
- Beautify adds consistent indentation; Minify collapses a query to one line.
- Formatting never changes what a query actually does — only its spacing.
- Doesn't validate SQL syntax or check that tables/columns exist.
- Beautify before reviewing or debugging; minify only right before embedding in code.
What, Who, When & Why
| What it's for | Beautifies a messy SQL query with proper indentation, or minifies a formatted query down to one line. |
|---|---|
| Who it's for | Developers and analysts reviewing, debugging, or sharing SQL queries. |
| When to use it | Before a code review, when debugging a dense unindented query, or when embedding a query as a single-line string in code. |
| Why it's needed | Dense, unindented SQL is hard to read and easy to misjudge — proper formatting makes logic errors and clause structure much easier to spot. |
| Best way to use it | Beautify before reviewing or debugging, and only minify right before embedding the final, tested query into application code. |
How to Use the SQL Formatter
- Paste your SQL query into the Input box — any length, any level of messiness.
- Click Beautify to add proper indentation and line breaks, or Minify to collapse it to one line.
- Review the formatted result in the Output box.
- Click Copy to grab the formatted query for use elsewhere.
Example: Beautifying a Query
A dense, single-line query like this:
select id, name, email from users where status = 'active' and created_at > '2026-01-01' order by name;
becomes properly indented and readable after beautifying:
SELECT
id,
name,
email
FROM users
WHERE status = 'active'
AND created_at > '2026-01-01'
ORDER BY name;
Running that same beautified query through Minify instead collapses it right back down to a compact single line — useful when the same query needs to be embedded as a string literal in application code, where line breaks can be inconvenient or require extra escaping.
Key Features
- Beautify mode — adds consistent indentation and line breaks to a messy query.
- Minify mode — collapses a formatted query into a single line, useful for embedding in code or logs.
- Works with SELECT, INSERT, UPDATE, DELETE, and other common SQL statement types.
- Instant, client-side formatting — no query is ever sent to a server.
- One-click copy of the result.
Practical Use Cases
- Code review: beautify a colleague's dense one-line query before reviewing or discussing it.
- Debugging: break a long, complex query into readable sections to spot logic errors more easily.
- Documentation: format queries consistently before pasting them into a wiki, ticket, or README.
- Embedding in code: minify a query to fit cleanly as a single string in application source code.
- Standardizing team style: beautify queries consistently so a team's SQL follows the same formatting conventions.
Tips for Best Results
- Beautify a query before sharing it in a code review or documentation, since consistent indentation makes logic errors much easier to spot.
- Minify only for embedding purposes — keep a beautified copy for your own reference and future edits.
- Run the Query Sanitizer first if your query has comments or a trailing semicolon you don't want carried through into the formatted output.
Related Terminology
SQL formatting (or "pretty-printing") refers to consistently indenting and spacing a query's clauses (SELECT, FROM, WHERE, etc.) to improve readability without changing what the query does. Minification is the opposite: removing unnecessary whitespace and line breaks to shrink the text, which doesn't affect how the database executes the query.
Important Considerations
Formatting is a text-transformation process and does not validate or execute your SQL — it won't catch syntax errors or check that tables and columns exist. Very complex queries with deeply nested subqueries may format in a way that still benefits from manual review for readability.
Related Tools
Once your query is formatted, the SQL Query Explainer can break down what it actually does in plain English. If you're removing comments or trailing semicolons before sharing a query, try the Query Sanitizer. For boilerplate starting points, browse the SQL Query Templates.
Frequently Asked Questions
How do I format a SQL query online?
Paste your query into the Input box and click Beautify — the tool adds consistent indentation and line breaks automatically.
Can I minify a SQL query to one line?
Yes, click Minify instead of Beautify to collapse a formatted query down to a single line, useful for embedding in code.
Does the formatter check if my SQL is valid?
No, it only reformats the text's spacing and line breaks — it doesn't validate syntax or check that your tables and columns exist.
Is my SQL query sent to a server when I use this tool?
No, formatting happens entirely in your browser, which makes it safe to use with queries that reference internal or sensitive table/column names.
Will formatting change what my query actually does?
No, formatting only changes spacing, indentation, and line breaks — the underlying query logic and results are completely unaffected.
WITH recent_orders AS (
SELECT
customer_id,
order_id,
order_date,
total_amount
FROM orders
WHERE order_date >= DATEADD(day, -30, GETDATE())
)
SELECT
customer_id,
COUNT(order_id) AS order_count,
SUM(total_amount) AS total_spent
FROM recent_orders
GROUP BY customer_id
ORDER BY total_spent DESC;
WITH RECURSIVE employee_hierarchy AS (
-- Anchor: top-level rows (no manager)
SELECT
employee_id,
manager_id,
employee_name,
1 AS level
FROM employees
WHERE manager_id IS NULL
UNION ALL
-- Recursive: join children to their parent's result
SELECT
e.employee_id,
e.manager_id,
e.employee_name,
eh.level + 1
FROM employees e
INNER JOIN employee_hierarchy eh
ON e.manager_id = eh.employee_id
)
SELECT *
FROM employee_hierarchy
ORDER BY level, employee_name;
-- Note: SQL Server / Oracle: drop the RECURSIVE keyword (just WITH employee_hierarchy AS (...))
SELECT
o.order_id,
c.customer_name,
o.order_date,
p.product_name,
oi.quantity
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id
LEFT JOIN order_items oi
ON o.order_id = oi.order_id
LEFT JOIN products p
ON oi.product_id = p.product_id
WHERE o.order_date >= '2026-01-01'
ORDER BY o.order_date DESC;
SELECT
DATE_TRUNC('month', order_date) AS order_month, -- PostgreSQL
-- FORMAT(order_date, 'yyyy-MM') AS order_month, -- SQL Server
-- DATE_FORMAT(order_date, '%Y-%m') AS order_month, -- MySQL
COUNT(*) AS order_count,
SUM(total_amount) AS revenue
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY order_month;
SELECT
customer_id,
order_id,
order_date,
total_amount,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY order_date DESC
) AS order_rank,
SUM(total_amount) OVER (
PARTITION BY customer_id
ORDER BY order_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS running_total
FROM orders;
CREATE PROCEDURE GetCustomerOrders
@CustomerId INT,
@StartDate DATE = NULL,
@EndDate DATE = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT
order_id,
order_date,
total_amount
FROM orders
WHERE customer_id = @CustomerId
AND (@StartDate IS NULL OR order_date >= @StartDate)
AND (@EndDate IS NULL OR order_date <= @EndDate)
ORDER BY order_date DESC;
END;
-- Call it: EXEC GetCustomerOrders @CustomerId = 101, @StartDate = '2026-01-01';
MERGE INTO customers AS target
USING staging_customers AS source
ON target.customer_id = source.customer_id
WHEN MATCHED THEN
UPDATE SET
target.customer_name = source.customer_name,
target.email = source.email,
target.updated_at = GETDATE()
WHEN NOT MATCHED THEN
INSERT (customer_id, customer_name, email, created_at)
VALUES (source.customer_id, source.customer_name, source.email, GETDATE());
#FACC15
rgb(250, 204, 21)
rgb(98%, 80%, 8%)
hsl(46, 96%, 53%)
hsv(46, 92%, 98%)
cmyk(0%, 18%, 92%, 2%)
Tools for analysts, developers & QA engineers
33 free, browser-based utilities — text and list tools, SQL helpers, converters, and small productivity apps. Everything runs locally; nothing you type or paste is ever uploaded.
For Analysts
Clean lists, build SQL fragments, and reshape data without opening a spreadsheet.
For Developers
Format SQL, convert data formats, and handle everyday text and encoding tasks.
For QA Engineers
Generate test data, compare text output, and sanitize queries before sharing them.