DevTools Pro · All tools · About

SQL Formatter

About the SQL Formatter

This SQL formatter turns a long, single-line query into readable SQL with each clause on its own line, consistent indentation and the keyword case you prefer. It understands MySQL, PostgreSQL, SQL Server and SQLite quoting rules, and it can also minify a query back to one line.

How the SQL is laid out

Major clauses such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT start a new line, and the columns or conditions under them are indented one level. Each column in a select list gets its own line, and every JOIN is placed on a new indented line.

AND and OR conditions break onto separate lines, except the AND that belongs to BETWEEN x AND y. CASE expressions put each WHEN and ELSE on its own line, and subqueries inside parentheses are indented as their own block.

Why the dialect setting matters

Dialects disagree on how strings, identifiers and comments are written. MySQL / MariaDB uses backtick identifiers, # comments and backslash escapes inside strings. PostgreSQL has dollar-quoted strings like $$ ... $$ for function bodies. SQL Server (T-SQL) quotes identifiers with [brackets] and uses #temp table names.

Picking the right dialect makes sure these pieces are recognized as single tokens, so the formatter never splits a string or breaks a quoted identifier. Text inside string literals, quoted identifiers and comments is always left exactly as written.

Uppercase or lowercase SQL keywords?

SQL keywords are case-insensitive, so select and SELECT run the same. Uppercase keywords are the most common convention because they stand out from table and column names. Choose Preserve to leave the original casing alone, for example when matching an existing codebase style.

How to Use the SQL Formatter

  1. Paste your query into Input SQL, or click Load Sample to try it with an example.
  2. Set the Dialect to match your database: Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL) or SQLite.
  3. Choose an Indent of 2 spaces, 4 spaces or Tab, and a Keyword Case of UPPERCASE, lowercase or Preserve.
  4. Click Format SQL for a readable layout, or Minify to collapse the query onto one line.
  5. Use the copy button to grab the result, or the download button to save it as formatted.sql.

Frequently Asked Questions

Is my SQL sent to a server or database?
No. The query is tokenized and formatted in your browser. It is never executed, uploaded or stored.
Does formatting change what my query does?
No. Only whitespace and, if you choose, keyword case change. String literals, quoted identifiers and comments stay exactly as written.
Does the formatter validate my SQL?
Only partly. It warns about unterminated strings or comments and unbalanced parentheses, but it does not check table names or full grammar. Run the query against your database to be sure it is valid.
Which dialect should I choose for MariaDB or Snowflake?
Use MySQL / MariaDB for MariaDB. For other databases, Standard SQL works for most queries; switch to the dialect whose quoting your database shares if strings or identifiers are split incorrectly.
Are comments kept?
Format SQL keeps -- and /* */ comments (and # comments in MySQL mode). Minify removes them to keep the output on one line.
Can I format several statements at once?
Yes. Separate them with semicolons and each statement is formatted in turn, with a blank line between statements.

Related tools