How to format SQL
- Paste a query, even a long single line copied from a log, ORM debug output or a BI tool.
- Press Format. Each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY and so on) starts on its own line, columns and conditions are listed one per line, joins are indented under FROM, and subqueries are indented inside their parentheses.
- Choose UPPERCASE, lowercase or unchanged keywords and your preferred indent.
- Press Minify to collapse the query back to one line, with comments removed, for embedding in code or a config file.
Why format SQL?
Readable SQL is easier to review, debug and maintain. With one condition per line, it is obvious which filters apply, where an AND or OR changes the logic, and which columns are grouped. Formatted queries also produce cleaner diffs in code review.
The formatter works with standard SQL and the common dialects: PostgreSQL (including :: casts, $1 parameters and ON CONFLICT), MySQL (backtick identifiers), SQL Server (bracketed identifiers, TOP), SQLite and BigQuery-style queries. Strings and quoted identifiers are never changed, comments are kept, and BETWEEN … AND … stays on one line. Several statements separated by semicolons are formatted one after another.
It also does a quick sanity check and warns about unbalanced parentheses or an unclosed string, two common causes of confusing syntax errors.
Privacy
The formatter is written in plain JavaScript and runs in your browser. Queries, which often contain table names and data, are never uploaded.
Does formatting change what my query does?
No. Only whitespace and keyword case change. String values, identifiers and comments are preserved exactly.
Should SQL keywords be uppercase?
SQL is case-insensitive for keywords, so it is a style choice. Uppercase keywords are the most common convention because they stand out from table and column names.
Does it validate my SQL?
It checks for unbalanced parentheses and unclosed strings, but not full syntax. Run the query in the SQL Playground to test it against a real SQLite database.