SQL Formatter
Paste any SQL query and get a clean, indented version in a click. Choose your dialect — Postgres, MySQL, SQLite, BigQuery, Snowflake, MSSQL and more — and tune indent, keyword case, operator spacing, and semicolon placement to match your team's style. Powered by sql-formatter, running entirely in your browser.
Messy one-liners become readable queries
A cramped query with joins and aggregates becomes a structured statement with consistent indentation and aligned clauses.
select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.created_at>now()-interval '30 days' group by u.id,u.name having count(o.id)>0 order by orders desc limit 100;
SELECT u.id, u.name, COUNT(o.id) AS orders FROM users u LEFT JOIN orders o ON o.user_id = u.id WHERE u.created_at > NOW() - INTERVAL '30 days' GROUP BY u.id, u.name HAVING COUNT(o.id) > 0 ORDER BY orders DESC LIMIT 100;
What you'll use this for
Cleaning up SQL pasted from logs, ORMs, code-review tools, or BI reports — anywhere a wall-of-text query needs to become something you can actually read.
Debugging slow queries
Format the EXPLAIN-bound query so you can see exactly which join or subquery is blowing up — clauses on their own lines.
Code review
Drop a coworker's WHERE-cluster onto the page before commenting. Easier to spot a missing predicate when it's not on line 1.
ORM-generated SQL
Active Record, Prisma, Sequelize, Hibernate — they all emit dense SQL. Format it to verify what's really hitting the database.
Docs & notebooks
Paste cleaned-up SQL into runbooks, Notion, or Jupyter cells so the next person on call doesn't squint at a one-liner.
How to format SQL
Paste the query
Drop the SQL into the left editor. Multi-statement scripts, CTEs, and DDL all work.
Pick your dialect
Postgres, MySQL, BigQuery, Snowflake, MSSQL, and more. The dialect affects keyword recognition and quirks like QUALIFY or backtick quoting.
Tune indent and case
2 spaces, 4 spaces, or tabs. Uppercase keywords for SQL-classic style, lowercase for a softer look, or preserve what you typed.
Copy or download
Grab the formatted text or save it as .sql. Hit Minify if you need to flatten it back to one line.
Frequently asked questions
PostgreSQL, MySQL, MariaDB, SQLite, BigQuery, Snowflake, Transact-SQL (MSSQL), Redshift, Spark SQL, Hive, and DB2. Switch dialects from the dropdown — the formatter adjusts to dialect-specific keywords like QUALIFY, LATERAL, or STRUCT<...>.
Yes. Both -- line comments and /* ... */ block comments are preserved and placed on their own lines next to the statements they describe.
Yes. WITH clauses, recursive CTEs, OVER (PARTITION BY ...) expressions, LATERAL joins, and other modern SQL constructs are formatted correctly. The formatter splits each CTE onto its own block and aligns window frames.
No. The sql-formatter library is loaded from a CDN once, then everything happens locally in your browser. Your query never reaches our servers — copy-paste it without thinking about it.
BigQuery has its own keywords (STRUCT, UNNEST, QUALIFY, EXCEPT (col1, col2) in SELECT), backtick-quoted identifiers, and table syntax like `project.dataset.table`. Selecting BigQuery as the dialect makes the formatter aware of these so they're laid out correctly instead of being treated as identifiers in a generic dialect.
About this SQL formatter
This tool wraps the open-source sql-formatter JavaScript library — the same engine used by many editor plugins. It runs entirely in your browser, so the SQL you paste never crosses a network boundary.
What it does
- Breaks long statements onto multiple lines — SELECT lists, JOIN chains, and WHERE predicates get a line each.
- Normalizes keyword case — uppercase, lowercase, or preserve.
- Preserves your literals exactly — string values, numbers, identifiers stay untouched.
- Handles dialect quirks — backticks vs double-quotes,
TOPvsLIMIT, etc.
What it doesn't do
- Validate semantics. The formatter is a parser, not an executor — it won't tell you that
users.iddis a typo. - Rewrite queries. Joins, subqueries, and aggregates are preserved as written — only whitespace changes.
- Execute SQL. Connect to your database from a real client to actually run anything.