Skip to content

Format SQL queries

Beautify or minify SQL for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery, Oracle and 14 more dialects with your choice of style, right in your browser.

Formatted
Press Format SQL to beautify your query.
Runs in your browser · no uploadHow it works

How to use SQL formatter

  1. 1

    Paste your SQL

    Paste a query or a whole script, or open a .sql file; Sample shows a messy query to try.

  2. 2

    Choose the dialect

    Pick your database so its quoting, operators and keywords are recognised correctly.

  3. 3

    Set the style

    Choose keyword case, indentation, comma position and layout to match your team’s conventions.

  4. 4

    Format and copy

    Press Format SQL or Minify, then copy the highlighted result or download it as .sql.

Limits and Pro

Free with no sign-up: 20 dialects, .sql files up to 10 MB, and scripts that format within 20 seconds; outputs over 600,000 characters are previewed in part and copied or downloaded in full.

Pro removes the ads; the formatter itself is the same on every plan. See Pro

About SQL formatter

Paste a one-line query from a log, an ORM's debug output or a colleague's chat message and this formatter lays it out the way a careful person would: one clause per line, selected columns and joins indented under their keyword, and subqueries nested so the structure is visible at a glance. It understands 20 SQL dialects — standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server T-SQL, SQLite, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, Trino, DuckDB, ClickHouse, Hive, Db2, Db2 for i, SingleStore, TiDB and Couchbase N1QL — so dialect syntax such as backtick identifiers, square brackets, :: casts or dollar-quoted strings is kept intact.

You choose the house style: keywords in uppercase, lowercase or as written; function names and data types the same way; two spaces, four spaces or tabs; commas at the end or the start of lines; AND and OR before or after the line break; and a standard or tabular layout that lines keywords up in a column. Multi-statement scripts are separated by a blank line. Minify does the opposite, removing comments and extra whitespace while keeping strings, quoted names and optimizer hints untouched.

The output is syntax-highlighted and can be copied or downloaded as a .sql file. Formatting uses the open-source sql-formatter library, loaded the first time you press Format, and runs in a background worker so long scripts don't block the page.

The formatter changes only whitespace and letter case. It doesn't validate table or column names, run the query, or rewrite it for performance, and stored procedures with unusual vendor syntax may need the closest dialect.

Privacy

SQL is formatted inside your browser by a Web Worker, so queries containing table names, customer data or credentials are never sent to a server. Your dialect and style choices are saved in local storage; the SQL itself is not stored.

Features

20 SQL dialects

MySQL, PostgreSQL, SQL Server, Oracle, BigQuery, Snowflake and 14 more.

Your house style

Keyword case, indentation, leading or trailing commas, AND/OR placement and tabular layout.

Minify too

Strip comments and whitespace for embedding SQL in code, keeping strings and hints intact.

SQL formatter: frequently asked questions

Does formatting change what my query does?
No. Only whitespace, line breaks and the letter case of keywords, functions and data types change; identifiers, string literals and comments are kept exactly. Keyword case is safe because SQL keywords are case-insensitive. If you choose to lowercase or uppercase identifiers in other tools, beware that PostgreSQL treats quoted names as case-sensitive, which is why this formatter leaves them alone.
Why do I get a parse error?
The formatter needs to recognise the statement structure, so an unbalanced parenthesis, a missing keyword or syntax from another database stops it. The message gives the line and column and what it expected there. Pick the dialect your database uses — square-bracket identifiers need SQL Server, backticks need MySQL, MariaDB or BigQuery — and check for unfinished statements at the end.
Should commas go at the start or the end of the line?
Trailing commas are the most common style and what most tools produce. Leading commas make it easy to comment out the last column and keep diffs to one line when you add a column, which is why some data teams prefer them. Pick whichever your team uses; the option only applies to the standard layout.
Can it format stored procedures and scripts with many statements?
Yes. Paste a full script and each statement is formatted and separated by a blank line, including CREATE TABLE, INSERT, UPDATE, MERGE and common procedural blocks. Vendor-specific procedural code, such as complex T-SQL batches with GO separators or PL/SQL packages, may not be fully understood; choose the matching dialect and format smaller blocks if a section fails.
What does Minify remove?
Minify deletes -- and /* */ comments (and # comments in MySQL and MariaDB), collapses runs of spaces and line breaks into single spaces and removes spaces next to commas and parentheses. String literals, quoted identifiers and optimizer hints written as /*+ … */ or MySQL's /*! … */ are kept, so the minified query runs exactly like the original.
All developer tools