Skip to content

SQL Formatter

Format SQL for PostgreSQL, MySQL, SQL Server, Oracle and SQLite into readable queries.

Runs in your browser. Nothing is uploaded.

SQL input

Keywords
Indent
Layout
Examples

Formatted SQL

22 lines
SELECT
  o.id,
  o.total,
  c.name AS customer,
  count(l.id) AS line_count
FROM
  orders o
  JOIN customers c ON c.id = o.customer_id
  LEFT JOIN order_lines l ON l.order_id = o.id
WHERE
  o.status = 'shipped'
  AND o.created_at >= '2026-01-01'
GROUP BY
  o.id,
  o.total,
  c.name
HAVING
  count(l.id) > 2
ORDER BY
  o.total DESC
LIMIT
  25;

How to use the SQL Formatter

  1. Paste one or more SQL statements into the input.
  2. Choose the database dialect, keyword case and indentation.
  3. The formatted SQL appears as you type. Copy it or download it as a .sql file.

Why format SQL?

SQL generated by tools, logs and ORMs is usually one long line. Formatting puts each clause on its own line and indents subqueries, so joins, filters and grouping can be read and reviewed. In version control, formatted SQL produces small, clear diffs.

Example

Before
select id, name from accounts where region = 'EMEA' and active = true order by name
After
SELECT
  id,
  name
FROM
  accounts
WHERE
  region = 'EMEA'
  AND active = TRUE
ORDER BY
  name

Choosing the dialect

Databases quote identifiers and write some keywords differently: MySQL uses backticks, SQL Server square brackets, PostgreSQL double quotes. Choosing the right dialect lets the formatter read those correctly. If parsing fails, try “Standard SQL” or the dialect your database actually uses.

SQL and Salesforce

Salesforce developers meet SQL on the other side of integrations: data warehouses, middleware, Heroku Postgres and external objects through Salesforce Connect. Salesforce’s own query language, SOQL, looks similar but is not SQL — it has no joins in the usual sense and uses relationship paths such as Account.Name instead.

Features and limitations

What it does

  • Supports standard SQL, PostgreSQL, MySQL, SQL Server (T-SQL), Oracle (PL/SQL) and SQLite.
  • Formats SELECT, INSERT, UPDATE, DELETE, CREATE and multi-statement scripts, including CTEs and window functions.
  • Upper-case, lower-case or preserved keywords; 2 or 4 space indentation; standard or tabular layout.
  • Comments and string literals are kept exactly as written.
  • Explains where parsing failed, with line and column.

What it does not do

  • Formatting only: it does not run queries or check them against a database schema.
  • Stored procedure bodies with vendor-specific control flow may format less neatly.
  • For Salesforce SOQL, use the SOQL Formatter, which understands relationship queries and bind variables.

Questions about the SQL Formatter

No. Formatting runs in your browser. Queries often reveal table names and data; they never leave your device.

No. Only whitespace and, if you choose, the case of keywords change. Identifiers, strings and comments are kept as written.

Simple SOQL may format, but relationship subqueries and bind variables will not be handled properly. Use the SOQL Formatter for Salesforce queries.

It aligns keywords in a left column and the rest of each clause in a right column, a style some teams prefer for long queries.

It uses the open-source sql-formatter library, loaded only on this page and run entirely in your browser.