SQL Formatter

Turn one long unreadable query into indented SQL you can review — in your browser, with your query never leaving the tab.

The first format downloads a 79 KB SQL formatter from jsDelivr. Your query is never uploaded — it is formatted in this tab.

🔒 Runs entirely in your browser — nothing you type is uploaded or stored on a server.

Paste a query that arrived as one 400-character line and get back something you can actually read: clauses on their own lines, joins lined up, nesting indented. It handles 16 dialects — standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Redshift, Spark, Hive, Db2, SingleStore, Trino and TiDB — because dialects disagree about enough syntax that a one-size formatter mangles half of them.

Also on Txtset: do the same for a JSON document · turn query results into JSON.

There is a reason to care where a SQL formatter runs. Real queries carry table names, column names and often literal values from production. Pasting those into a website means handing your schema to somebody else's server. Nothing you type here is uploaded. The first time you press Format, the page downloads the sql-formatter library (79 KB) from a CDN — pinned to version 15.6.9 and verified with Subresource Integrity — and from then on the work happens entirely in this tab, offline if you like.

Minify goes the other way: it strips -- and /* */ comments and collapses the query to a single line, which is what you want when a query has to live inside a config file or a shell command. The comment stripper is quote-aware, so a -- inside a string literal survives instead of eating the rest of your query.

One honest limit: this is a formatter, not a parser or a linter. It will lay out a query with a syntax error just as happily as a correct one, and it will not tell you the query is wrong. Run it against your database for that.

How to use

  1. Paste your SQL into the box.
  2. Pick the dialect you are writing for — it changes how quoting, functions and dialect-specific keywords are handled.
  3. Choose whether keywords should be uppercased, lowercased or left as typed, and pick an indent width.
  4. Press Format for readable SQL, or Minify for a single line with comments removed.
  5. Copy the result, or download it as a .sql file.

Examples

A one-line SELECT
select u.id,count(o.id) from users u left join orders o on o.user_id=u.id group by u.id comes back with each clause on its own line and the join indented under it.
Keyword case
Set keywords to UPPERCASE and select … from … where becomes SELECT … FROM … WHERE without touching your table or column names.
Minify with a comment
SELECT 1 -- note minifies to SELECT 1, but SELECT '-- not a comment' keeps its string intact.

Frequently asked questions

Is my query sent to a server?
No. The formatter library is downloaded once from jsDelivr on your first Format, and after that every keystroke is handled in this tab. Your SQL — table names, column names, literal values — never crosses the network.
Which dialects are supported?
Sixteen: standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, Hive, Db2, SingleStore, Trino and TiDB. Picking the right one matters because dialects differ on identifier quoting and on which words are reserved.
Will it tell me if my SQL is invalid?
No, and it should not pretend to. A formatter lays out text; only your database knows whether the query is valid against your schema. Malformed SQL usually comes back oddly indented, which is a hint, not a verdict.
What exactly does Minify remove?
Line comments starting with --, block comments between /* and */, and redundant whitespace. It is quote-aware: a comment marker inside a string literal is left alone rather than swallowing the rest of the query.
Does it work offline?
After the first format, yes — your browser caches the library. The very first format needs a connection.
Can I format several statements at once?
Yes. Statements separated by semicolons are each formatted and separated by a blank line.