SQL Formatter
Paste a query to format it with clean indentation and consistent keyword case, for 12 SQL dialects. Or minify it to a single line.
Last updated
SQL
Formatted SQL
ConvertedSELECT u.id, u.email, COUNT(o.id) AS order_count, SUM(o.total) AS revenue FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.active = TRUE AND o.created_at >= '2026-01-01' GROUP BY u.id, u.email HAVING COUNT(o.id) > 5 ORDER BY revenue DESC LIMIT 20;
20 lines · 284 characters (input 258)
Keyboard shortcuts:Ctrl ↵Copy outputCtrl SDownloadCtrl KSearch tools
How to use the SQL Formatter
Paste your SQL
Paste one query or several. They can come from logs, an ORM or a migration.
Pick the dialect
Choose PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and more, so dialect-specific syntax is understood.
Set the style
Choose UPPERCASE, lowercase or as-typed keywords, and 2 spaces, 4 spaces or tabs.
Copy the result
Copy or download the formatted SQL, or switch to Minify for a compact one-liner.
Features
- Formats SQL as you type, with each clause on its own line
- 12 dialects: Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL and Trino
- Keyword, function and data-type case: UPPERCASE, lowercase or as typed
- 2-space, 4-space or tab indentation
- Minify mode removes comments and extra whitespace without touching quoted strings
- Multiple statements are separated by a blank line
- Remembers your dialect and style settings (never your SQL)
- Copy, or download as .sql — also with Ctrl/Cmd + Enter and Ctrl/Cmd + S
Privacy
Your queries are processed by JavaScript in your browser tab. Nothing is uploaded or stored, and the page's security policy blocks it from sending data to any other site.
Examples
Format a query from the logs
A one-line PostgreSQL query becomes readable, one clause per line.
SQL
select d.id, d.name, max(t.recorded_at) as last_seen from devices d join telemetry t on t.device_id = d.id where t.recorded_at > now() - interval '1 day' group by d.id, d.name order by last_seen desc;Formatted (PostgreSQL)
SELECT d.id, d.name, MAX(t.recorded_at) AS last_seen FROM devices d JOIN telemetry t ON t.device_id = d.id WHERE t.recorded_at > NOW() - INTERVAL '1 day' GROUP BY d.id, d.name ORDER BY last_seen DESC;Several MySQL statements
Each statement is formatted, with a blank line between them.
SQL
create table users (id int auto_increment primary key, email varchar(255) not null unique, created_at timestamp default current_timestamp); insert into users (email) values ('ada@example.com'), ('alan@example.com');Formatted (MySQL)
CREATE TABLE users ( id INT auto_increment PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, created_at timestamp default current_timestamp ); INSERT INTO users (email) VALUES ('ada@example.com'), ('alan@example.com');Minify for a config file
Comments and extra whitespace go; the spaces inside the string stay. Loads in Minify mode.
SQL
SELECT id, email -- the login FROM users WHERE status = 'active user' /* only recent */ AND created_at > '2026-01-01';Minified
SELECT id,email FROM users WHERE status = 'active user' AND created_at > '2026-01-01';
Understanding SQL formatting
Why format SQL?
Queries copied from logs or generated by ORMs usually arrive on one line. Putting each clause on its own line makes joins, filters and grouping easy to scan, makes reviews and diffs clearer, and helps you spot a missing join condition or an accidental cross join.
select id, email from users where active = true order by created_at desc
→
SELECT
id,
email
FROM
users
WHERE
active = TRUE
ORDER BY
created_at DESCWhy the dialect matters
Databases quote identifiers and write parameters differently: PostgreSQL uses "double quotes" and $1, MySQL uses ` backticks and ?, SQL Server uses [brackets] and @name. Choosing the right dialect lets the formatter recognise these, along with dialect-only keywords such as RETURNING, TOP or QUALIFY`.
SQL style conventions
- UPPERCASE keywords with lowercase identifiers is the most common style, because it separates SQL from your names at a glance.
- One column per line makes diffs show exactly which column changed.
- Put each JOIN on its own line with its ON condition directly after it.
- Pick one style for the team and let a formatter apply it, so reviews focus on logic, not whitespace.
Frequently asked questions
Which SQL dialects are supported?
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL and Trino / Presto.
Why do I get a parse error?
The formatter has to understand the query's structure. Errors usually mean incomplete SQL, a dialect-specific feature with the wrong dialect selected, or template placeholders that aren't valid SQL. Try another dialect, or replace placeholders with sample values.
Does formatting change what my query does?
No. Only whitespace and the case of keywords, functions and data types change. Identifiers and string literals are left exactly as written.
What does Minify do?
It removes comments and collapses whitespace so the query fits on one line, without changing anything inside quoted strings or identifiers.
Can I format several statements at once?
Yes. Paste them separated by semicolons; each one is formatted, with a blank line between statements.