SQL formatter

Paste a SQL query to put each clause on its own line, indent the conditions and uppercase the keywords.

This free online SQL beautifier works in your browser. Everything runs in your browser. What you type is not sent anywhere. All inputs and calculations run locally on your device without server uploads; details on browser processing and storage are set out in the privacy policy.

How queries are laid out

Each main clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY, LIMIT) starts a new line. Columns in a list each get their own line, and AND, OR and ON conditions are indented under the clause they belong to. Text in quotes and comments is never changed, so 'a, b' stays one value.

Works with

Standard SQL as used by MySQL, MariaDB, PostgreSQL, SQLite, SQL Server and Oracle. Vendor-specific syntax is kept as written.

Worked example: Formatting a 1-line SQL query with a CTE, LEFT JOIN, and window function

Suppose you pull a slow single-line query out of an application query log:

with monthly_totals as (select user_id, sum(amount) as total_spent from orders where status = 'paid' and created_at >= '2026-01-01' group by user_id) select u.id, u.email, m.total_spent from users u left join monthly_totals m on u.id = m.user_id where m.total_spent > 5000 order by m.total_spent desc limit 25;

With Uppercase keywords enabled, the formatter uppercases SQL reserved words (WITH, SELECT, FROM, LEFT JOIN, WHERE, GROUP BY, ORDER BY) while keeping table/column identifiers and 'paid' string literals untouched:

WITH monthly_totals AS (
  SELECT
    user_id,
    SUM(amount) AS total_spent
  FROM orders
  WHERE status = 'paid'
    AND created_at >= '2026-01-01'
  GROUP BY user_id
)
SELECT
  u.id,
  u.email,
  m.total_spent
FROM users u
LEFT JOIN monthly_totals m
  ON u.id = m.user_id
WHERE m.total_spent > 5000
ORDER BY m.total_spent DESC
LIMIT 25;

Limits and what this tool cannot do

  • Formats layout only (does not validate table schemas or optimize query plans): The formatter tokenizes SQL keywords, identifiers, operators, and comments to indent clauses cleanly; it does not connect to a database, check if column names exist, or run EXPLAIN ANALYZE.
  • Procedural SQL blocks (PL/pgSQL, T-SQL, PL/SQL stored procedures): Standard SELECT, INSERT, UPDATE, DELETE, and CREATE TABLE DDL statements format cleanly, whereas vendor-specific procedural loops (DECLARE ... BEGIN ... EXCEPTION ... END $$) have dialect nuances.

Questions

Will formatting change my query’s result?

No. Only spacing and the case of keywords change. Quoted strings and names are left exactly as they are.

Can I keep lowercase keywords?

Yes. Turn off Uppercase keywords.

Is my query sent anywhere?

No. Everything runs in your browser. What you type is not sent anywhere.

Does Uppercase Keywords modify text inside single-quoted strings like 'select_option'?

No. The tokenizer distinguishes SQL keywords from single-quoted string literals ('...'), double-quoted/backticked identifiers ("...", ` ... ), and -- or /* */` comments, so your data literals are never altered.

Which SQL dialects are supported?

Standard ANSI SQL as well as PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (T-SQL), Oracle, BigQuery, and Snowflake query syntax.

Are my proprietary database queries sent to a server?

No. Tokenizing and formatting run locally inside your browser tab.

Last reviewed .

Related converters and guides