SQL Formatter

Format SQL into a consistent, reviewable shape with keyword casing options.

Database Runs in your browser
SQL
Formatted SQL

Nothing formatted yet

Paste a query and press Format. String literals and comments are preserved exactly, so formatting cannot change what it means.

Runs entirely in your browser. Your data isn't uploaded — this page makes no network request with anything you type, which you can verify in your browser's network tab. How this works.

What is the SQL Formatter?

A query that arrives as one 400-character line cannot be reviewed, and a query formatted differently by every author produces diffs nobody can read. Consistent formatting is what makes SQL reviewable in a pull request.

This formatter breaks clauses onto their own lines, indents nested expressions and subqueries, aligns join conditions, and normalises keyword casing — while leaving string literals, comments and identifier quoting exactly as they were.

How to use it

  1. Paste your SQL, or upload a .sql file.
  2. Choose keyword casing (upper, lower or unchanged) and indentation width.
  3. Press Format (or Ctrl/Cmd + Enter).
  4. Copy the formatted query, or download it.

Example

A one-line query, reflowed for review.

Input
select u.id,u.email from users u join orders o on o.user_id=u.id where o.total>100 order by u.id
Result
SELECT u.id,
       u.email
FROM users u
JOIN orders o
  ON o.user_id = u.id
WHERE o.total > 100
ORDER BY u.id

Features

  • Clause-per-line layout with indented subqueries and CTEs
  • Keyword casing normalisation without touching identifiers
  • String literals and comments preserved verbatim
  • Handles multiple statements in one input
  • Configurable indentation width and comma placement

Frequently asked questions

Which SQL dialects are supported?
Formatting is dialect-tolerant rather than dialect-specific: it works on PostgreSQL, MySQL, SQLite, SQL Server and Oracle syntax because it operates on tokens rather than a full parse. Very dialect-specific constructs are passed through unchanged rather than reflowed.
Will formatting change what my query does?
No. Only whitespace and keyword casing change, and neither is significant outside string literals — which are left alone.
Is my query sent anywhere?
No. Formatting runs in your browser, which matters because real queries often contain table names, business logic and sometimes literal values from production.
Esc

Loading the catalog…