Skip to content

SQL Formatter

Turn long or messy SQL into readable, consistently indented queries, for PostgreSQL, MySQL, SQL Server, SQLite, BigQuery, Snowflake and more.

  • Free, no sign-up
  • Runs in your browser
  • Sources cited

One or more statements. Strings, comments and quoted names are kept as written.

Formatted SQL

Statements
1
Lines
20

Everything runs in your browser. Nothing you enter is uploaded.

How to use the SQL formatter

  1. Paste the SQL

    Paste a query or a whole script, or open a .sql file. It is formatted as you type.

  2. Pick the dialect

    Choose the database, so its own syntax, such as square-bracket names in SQL Server or backticks in MySQL, is understood.

  3. Set the style

    Choose the case of keywords, names and functions, the indent, an aligned layout, and where AND and OR go.

  4. Copy or download

    Copy the formatted SQL or download it as a .sql file.

How SQL formatting works

SQL ignores most whitespace, so a query on one line and the same query spread over many lines run identically. Formatting only changes the layout: each clause, such as SELECT, FROM, WHERE and GROUP BY, starts a new line, the items under it are indented, and joins and conditions line up so the structure is visible at a glance.

The tool uses the open-source sql-formatter library, which reads the SQL into tokens before laying it out. That is why the dialect matters: databases quote names differently, as the PostgreSQL and SQL Server documentation describe, and each has its own keywords. Strings, comments and quoted names are kept exactly as written, and changing the case of names is optional because some databases treat quoted names as case-sensitive.

Formatting runs in your browser, so queries that contain table names or data never leave your device.

Worked example

The example query is a single line of 261 characters. Formatted for PostgreSQL with uppercase keywords it becomes 20 lines, starting “SELECT c.id, …”.

With lowercase keywords and four-space indents, “SELECT name FROM users WHERE active = TRUE” becomes “select ⏎ name ⏎ from ⏎ users ⏎ where ⏎ active = true”.

Understanding the result, and common mistakes

  • The wrong dialect. If formatting fails or looks odd, check that the dialect matches the database.
  • Unclosed quotes. A missing closing quote makes the rest of the script look like one string.
  • Changing name case on a case-sensitive database. Keep names as written unless you are sure.

Frequently asked questions

Does formatting change what the query does?

No. Only spaces, line breaks and, if you choose, keyword case change.

Can it format several statements?

Yes. Statements separated by semicolons are each formatted, with blank lines between them.

Is my SQL sent anywhere?

No. It is formatted in your browser.

Sources

  1. sql-formattersql-formatter contributors · retrieved Nov 14, 2026
  2. SQL Syntax: Lexical StructurePostgreSQL Global Development Group · retrieved Nov 14, 2026
  3. Transact-SQL syntax conventionsMicrosoft · retrieved Nov 14, 2026

About these results

  • SQL is formatted in your browser. Nothing you paste is uploaded.