How to use it
- Paste one or more SQL statements, or press “Try an example”.
- Choose the dialect of your database so its keywords, quoting and operators are recognised.
- Set keyword case and indentation. The formatted query appears on the right as you type.
- Press Minify for a single-line version, then copy the result or download it as a .sql file.
How it works
Formatting uses the open-source sql-formatter library. It splits the query into tokens using the rules of the dialect you choose, puts each major clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY…) on its own line, indents the column lists and conditions, and applies your keyword case. It changes whitespace and, if you ask, the letter case of keywords; identifiers, string literals and comments are kept. Choosing the right dialect matters: for example, backticks quote names in MySQL, square brackets in SQL Server, and $$ starts a function body in PostgreSQL.
The formatter is a layout tool, not a database. It does not check that tables or columns exist and does not validate the full grammar, so some invalid SQL is formatted without complaint. When it cannot make sense of the input, for instance an unclosed parenthesis, it reports the line and column where it stopped.
Minify works differently: it keeps every token and only collapses each run of whitespace into a single space and removes comments (optimizer hints such as /*+ INDEX(t) */ and MySQL /*! … */ comments are kept, because they change behaviour). Strings, quoted identifiers and dollar-quoted bodies are copied unchanged. If a quote or comment is never closed, minify stops with an error rather than guessing.
Examples
Reading a query from a log
A slow-query log shows one 400-character line. With the MySQL dialect and uppercase keywords, it becomes a readable block where each JOIN and WHERE condition sits on its own line, making the missing index easy to spot.
Consistent style for code review
A team formats every migration with PostgreSQL dialect, lowercase keywords and 4-space indentation before committing, so diffs only show real changes.
Embedding SQL in code
Minify turns a commented, multi-line report query into one line such as SELECT id, name FROM users WHERE active = 1 ORDER BY name, ready to paste into a string in a script.
Frequently asked questions
Which databases are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, Hive, Trino/Presto, DuckDB, IBM Db2, SingleStoreDB, TiDB and Couchbase N1QL.
Will formatting change what my query does?
It should not: only whitespace and, if selected, keyword case change. Keyword case does not matter in SQL. Still, review generated output before running it on production data, especially for unusual dialect features.
Why did I get “could not be formatted”?
The tokenizer met something it could not place, often an unclosed bracket or quote, or syntax from a different dialect. Check the line and column in the message and make sure the selected dialect matches your database.
Does it validate my SQL?
No. It is not connected to a database and does not know your schema. A query can be formatted and still fail when you run it.
Privacy
Your SQL is formatted in your browser with JavaScript. It is not uploaded, stored or included in analytics, and the tool never connects to a database.