SQL Formatter & Beautifier
Paste a messy query and get clean, consistently indented SQL. Supports 17 dialects, keyword casing and a one-click minifier, all in your browser.
Runs in your browserNo sign-upNothing uploaded
How to use the SQL Formatter
- Paste one or more SQL statements into the input box, or open a
.sqlfile. - Choose your database dialect so its syntax, such as
::casts,[brackets], backticks or$$strings, is parsed correctly. - Set keyword case (UPPER, lower or preserve), indentation and the number of blank lines between statements.
- Switch to Minify to strip comments and whitespace for logs, ORMs or URL parameters.
- Copy the result or download it as a
.sqlfile.
Why format SQL?
Queries copied from ORM logs, query plans or application code usually arrive as one long line. Putting each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) on its own line and indenting columns and conditions makes the logic readable. It also makes code review diffs smaller and helps you spot a missing join condition or a misplaced OR.
SQL style conventions
- Uppercase keywords (
SELECT,WHERE) separate SQL syntax from table and column names. Most style guides recommend this, though lowercase is popular in dbt and analytics teams. - One column per line makes adding or removing columns a one-line diff.
- Consistent indentation (2 or 4 spaces) inside clauses and subqueries shows the nesting at a glance.
- Statement terminators: end every statement with
;so multi-statement scripts are unambiguous.
Supported SQL dialects
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (T-SQL), Oracle PL/SQL, Google BigQuery, Snowflake, Amazon Redshift, Spark SQL, Trino/Presto, Hive, IBM Db2, Couchbase N1QL, SingleStore and TiDB. If a query fails to parse, try a more specific dialect: @variables, $1 parameters and vendor-specific operators are only recognised in their own dialect.
What the minifier does
Minify mode removes --, # and /* */ comments, collapses whitespace and line breaks into single spaces, and drops spaces around commas and parentheses. String literals and quoted identifiers ('…', "…", `…`, […], $$…$$) are copied byte-for-byte, so the query's meaning never changes.
Frequently asked questions
Is my SQL sent to a server?
Does formatting change what the query does?
Why do I get a parse error on valid SQL?
::type casts or SQL Server for [bracketed] names and @params.