SQL Formatter

Format or minify SQL in your browser for PostgreSQL, MySQL, SQL Server, BigQuery, Snowflake, SQLite, Oracle and 12 more dialects. Choose spaces or tabs and upper, lower or preserved keyword case. Minify keeps string literals intact and turns -- comments into /* */ so the one-line query still runs.

About this tool

What is a SQL formatter?

A SQL formatter (or SQL beautifier) rewrites a query so each clause starts on its own line and nested parts are indented, which makes long queries much easier to read, review and debug. This tool uses the sql-formatter library and understands the syntax of 19 SQL dialects. It can also do the opposite and compress a query onto one line.

How to use

  1. Paste SQL into the editor, or drag and drop a .sql file onto it.
  2. Pick your database under Language (for example PostgreSQL, MySQL or Transact-SQL).
  3. Under Indent, choose Spaces (1–16) or Tab; under Case, choose Preserve, Upper or Lower for keywords.
  4. Click Format to beautify, or Minify to put the query on one line.
  5. Copy the result or download it as format.sql with the buttons in the editor corner.

Features

  • 19 dialects: BigQuery, DB2, DB2i, DuckDB, Hive, MariaDB, MySQL, N1QL, PL/SQL (Oracle), PostgreSQL, Redshift, SingleStoreDB, Snowflake, Spark, Standard SQL, SQLite, TiDB, Transact-SQL (SQL Server) and Trino
  • Keyword case: keep as typed, or convert keywords such as select / SELECT to upper or lower case
  • Indentation: any number of spaces from 1 to 16, or tabs
  • Minify: collapses whitespace outside quotes and converts -- line comments to /* */ block comments so nothing after them is commented out
  • Readable errors: if the SQL cannot be parsed, the first line of the parser error is shown
  • Byte size display and file drag and drop

Example

Input:

Output (PostgreSQL, 2 spaces, Upper):

FAQ

Why do I get a "Parse error"?

Either the SQL has a syntax error, or it uses syntax that the selected Language does not support (for example PostgreSQL-style ::int casts with MySQL, or [bracketed] identifiers with Standard SQL). Try choosing the dialect of the database the query was written for.

Does formatting change what my query does?

No. Only whitespace, line breaks and (if you choose Upper or Lower) the case of keywords change. Table names, column names and string values are not modified.

Is my SQL sent to a server?

No. Formatting and minifying run in your browser, so it is safe to paste queries that contain internal table names.