Skip to content
Esc
  • MQTT Topic MatcherTest MQTT topic filters with + and # wildcards against topics, and check ACL patterns.
  • JSON FormatterBeautify, minify and validate JSON instantly as you type.
  • JSON DiffCompare two JSON documents and see every added, removed and changed value by path.
  • JSON to TypeScriptGenerate TypeScript interfaces or Zod schemas from a sample JSON response.
  • Base64 Encoder/DecoderConvert text to Base64 and back, with full Unicode support.
  • UUID GeneratorGenerate random v4 UUIDs — one or many — in the format you need.
  • JWT DecoderDecode JSON Web Tokens to inspect the header, payload and expiry.
  • Timestamp ConverterConvert Unix timestamps to dates and dates to timestamps.
  • URL Encoder/DecoderPercent-encode and decode URLs, and break down query strings.
  • Hash GeneratorGenerate MD5, SHA-1, SHA-256 and SHA-512 hashes of text or files.
  • Regex TesterTest regular expressions with live match highlighting and groups.
  • YAML to JSON ConverterConvert YAML to JSON and JSON to YAML, with clear error locations.
  • SQL FormatterBeautify or minify SQL for PostgreSQL, MySQL, SQL Server and 9 more dialects.
  • Mock Data GeneratorGenerate realistic fake data for API mocks as JSON, CSV or SQL inserts.
  • HTTP Header AnalyzerGrade response headers: CSP, HSTS, cookies, CORS and caching, explained.
  • Webhook Signature VerifierVerify and generate webhook signatures for GitHub, Stripe, Slack, Shopify and more.
  • Cron Expression GeneratorBuild and explain cron schedules, with the next run times in any time zone.
  • .env File ValidatorFind syntax errors, duplicates and missing keys in .env files.
  • HTML to JSX ConverterConvert HTML to valid React JSX: className, style objects, self-closing tags.
  • SVG to React ComponentTurn SVG files into React icon components with props and currentColor.
  • Markdown EditorWrite Markdown with a live preview, GitHub tables and task lists, and HTML export.

↑ ↓ to moveEnter to openPaste data to open it in the right tool. Nothing leaves your browser.

SQL Formatter

Paste a query to format it with clean indentation and consistent keyword case, for 12 SQL dialects. Or minify it to a single line.

Last updated

SQL

Formatted SQL

Converted
SELECT
  u.id,
  u.email,
  COUNT(o.id) AS order_count,
  SUM(o.total) AS revenue
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = TRUE
  AND o.created_at >= '2026-01-01'
GROUP BY
  u.id,
  u.email
HAVING
  COUNT(o.id) > 5
ORDER BY
  revenue DESC
LIMIT
  20;

20 lines · 284 characters (input 258)

How to use the SQL Formatter

  1. Paste your SQL

    Paste one query or several. They can come from logs, an ORM or a migration.

  2. Pick the dialect

    Choose PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and more, so dialect-specific syntax is understood.

  3. Set the style

    Choose UPPERCASE, lowercase or as-typed keywords, and 2 spaces, 4 spaces or tabs.

  4. Copy the result

    Copy or download the formatted SQL, or switch to Minify for a compact one-liner.

Features

  • Formats SQL as you type, with each clause on its own line
  • 12 dialects: Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL and Trino
  • Keyword, function and data-type case: UPPERCASE, lowercase or as typed
  • 2-space, 4-space or tab indentation
  • Minify mode removes comments and extra whitespace without touching quoted strings
  • Multiple statements are separated by a blank line
  • Remembers your dialect and style settings (never your SQL)
  • Copy, or download as .sql — also with Ctrl/Cmd + Enter and Ctrl/Cmd + S

Privacy

Your queries are processed by JavaScript in your browser tab. Nothing is uploaded or stored, and the page's security policy blocks it from sending data to any other site.

Read the DevNest privacy policy

Examples

  • Format a query from the logs

    A one-line PostgreSQL query becomes readable, one clause per line.

    SQL

    select d.id, d.name, max(t.recorded_at) as last_seen from devices d join telemetry t on t.device_id = d.id where t.recorded_at > now() - interval '1 day' group by d.id, d.name order by last_seen desc;

    Formatted (PostgreSQL)

    SELECT
      d.id,
      d.name,
      MAX(t.recorded_at) AS last_seen
    FROM
      devices d
      JOIN telemetry t ON t.device_id = d.id
    WHERE
      t.recorded_at > NOW() - INTERVAL '1 day'
    GROUP BY
      d.id,
      d.name
    ORDER BY
      last_seen DESC;
  • Several MySQL statements

    Each statement is formatted, with a blank line between them.

    SQL

    create table users (id int auto_increment primary key, email varchar(255) not null unique, created_at timestamp default current_timestamp); insert into users (email) values ('ada@example.com'), ('alan@example.com');

    Formatted (MySQL)

    CREATE TABLE users (
      id INT auto_increment PRIMARY KEY,
      email VARCHAR(255) NOT NULL UNIQUE,
      created_at timestamp default current_timestamp
    );
    
    
    INSERT INTO
      users (email)
    VALUES
      ('ada@example.com'),
      ('alan@example.com');
  • Minify for a config file

    Comments and extra whitespace go; the spaces inside the string stay. Loads in Minify mode.

    SQL

    SELECT id,
           email   -- the login
    FROM   users
    WHERE  status = 'active  user'
      /* only recent */ AND created_at > '2026-01-01';

    Minified

    SELECT id,email FROM users WHERE status = 'active  user' AND created_at > '2026-01-01';

Understanding SQL formatting

Why format SQL?

Queries copied from logs or generated by ORMs usually arrive on one line. Putting each clause on its own line makes joins, filters and grouping easy to scan, makes reviews and diffs clearer, and helps you spot a missing join condition or an accidental cross join.

select id, email from users where active = true order by created_at desc

→

SELECT
  id,
  email
FROM
  users
WHERE
  active = TRUE
ORDER BY
  created_at DESC

Why the dialect matters

Databases quote identifiers and write parameters differently: PostgreSQL uses "double quotes" and $1, MySQL uses ` backticks and ?, SQL Server uses [brackets] and @name. Choosing the right dialect lets the formatter recognise these, along with dialect-only keywords such as RETURNING, TOP or QUALIFY`.

SQL style conventions

  • UPPERCASE keywords with lowercase identifiers is the most common style, because it separates SQL from your names at a glance.
  • One column per line makes diffs show exactly which column changed.
  • Put each JOIN on its own line with its ON condition directly after it.
  • Pick one style for the team and let a formatter apply it, so reviews focus on logic, not whitespace.

Frequently asked questions

Which SQL dialects are supported?

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL and Trino / Presto.

Why do I get a parse error?

The formatter has to understand the query's structure. Errors usually mean incomplete SQL, a dialect-specific feature with the wrong dialect selected, or template placeholders that aren't valid SQL. Try another dialect, or replace placeholders with sample values.

Does formatting change what my query does?

No. Only whitespace and the case of keywords, functions and data types change. Identifiers and string literals are left exactly as written.

What does Minify do?

It removes comments and collapses whitespace so the query fits on one line, without changing anything inside quoted strings or identifiers.

Can I format several statements at once?

Yes. Paste them separated by semicolons; each one is formatted, with a blank line between statements.