Quick access

Saved in this browser. Sign in to keep it on all your devices.

SQL Formatter

Format and beautify SQL queries instantly. Make your SQL readable and consistent.

Smart Formatting

Each clause on its own line, lists and conditions indented, subqueries nested. Strings and comments are never changed.

Minify Option

Put a whole query on one line, with comments removed, for logs, config files or code strings.

One-click Copy

Copy formatted or minified SQL directly to clipboard.

Supported SQL Keywords

SELECT FROM WHERE JOIN LEFT JOIN ORDER BY GROUP BY HAVING INSERT UPDATE DELETE UNION
35+
Keywords
2
Modes
100%
Free
0
Sign-up

Frequently Asked Questions

What is the difference between Format and Minify?

Format puts each clause on its own line and indents lists, conditions and subqueries, which makes a query easy to read and review. Minify puts the query on a single line and drops comments, which suits log messages and strings in code.

Does this support MySQL, PostgreSQL, and SQLite?

Yes. It formats SELECT, INSERT, UPDATE, DELETE, joins, subqueries and WITH queries, and it knows MySQL backticks and # comments, PostgreSQL casts, dollar quotes and JSON operators, and SQL Server square brackets.

Can I format multiple SQL statements at once?

Yes. Separate the statements with semicolons and each one starts on a new block, with a blank line between them.

What does the formatter leave on one line?

CASE expressions, window functions and CREATE TABLE column lists stay on one line, and procedural code such as stored procedures is only lightly spaced. The formatter does not check your SQL, so an unclosed quote or bracket shifts everything after it.

Version 1.1 Updated What's new

Release notes

  1. v1.1 Latest
    • Added an in-depth guide below the tool, written from what the tool actually does.
    • Text inside quotes and comments is no longer changed when formatting or minifying.
    • Lists, conditions, joins and subqueries are now indented properly.
    • Added keyword case and indent options.

About the SQL Formatter

The SQL formatter puts each clause (SELECT, FROM, WHERE, JOIN) on its own line with consistent indentation, which makes long queries easy to read and review.

How to use it

  1. 1 Paste your SQL query.
  2. 2 Choose the indent style and keyword case.
  3. 3 Copy the formatted SQL.

Frequently asked questions

Does formatting change the query result?

No. Only whitespace and letter case of keywords change, so the query returns the same data.

Does it check my SQL for errors?

It formats the query but does not run it against a database, so some errors only show up when you run it.

Should SQL keywords be uppercase?

SQL is not case-sensitive for keywords, but uppercase keywords are a common convention that makes queries easier to scan.

What the formatter changes and what it leaves alone

The query is first split into pieces: keywords, names, numbers, operators, strings and comments. Only the spaces and line breaks between those pieces change, plus the letter case of SQL keywords. Text in quotes is never touched, so 'Sign in' stays 'Sign in', a column written as "order" or `select` keeps its name, and comments stay word for word.

Function names such as COUNT, YEAR or DATE change case only when they are called with brackets. A column that happens to be called date or year keeps the spelling you gave it.

The layout it produces

SELECT
  c.name,
  COUNT(o.id) AS orders
FROM
  customers c
  LEFT JOIN orders o ON o.customer_id = c.id
    AND o.status = 'paid'
WHERE
  c.country = 'BD'
  AND c.created_at >= '2026-01-01'
GROUP BY
  c.name
ORDER BY
  orders DESC
LIMIT 20;
  • Each main clause starts a line, with its content indented below it.
  • Columns, tables, GROUP BY and ORDER BY items, SET assignments and inserted rows get one line each.
  • AND and OR start new lines in WHERE, HAVING and join conditions, except the AND inside BETWEEN.
  • A subquery in brackets is indented one level further and its closing bracket lines up with the line that opened it.
  • Several statements separated by semicolons are split with a blank line between them.

Pick uppercase, lowercase or the case you typed for keywords, and two spaces, four spaces or tabs for the indent, to match your team’s style.

Database dialects it understands

  • MySQL and MariaDB: `backtick` names, # comments and backslash escapes inside strings.
  • PostgreSQL: ::type casts, $1 placeholders, $$ dollar-quoted function bodies and the ->, ->>, #> and #>> JSON operators.
  • SQL Server: [square bracket] names.
  • SQLite and standard SQL: "double-quoted" names and '' to escape a quote inside a string.

CASE expressions, window functions such as ROW_NUMBER() OVER (…), and CREATE TABLE column lists stay on one line. The formatter does not run or check the query, so an unclosed quote shifts the layout of everything after it, which is a quick way to spot one.

Minify, comments and code reviews

Minify puts the query on a single line, handy for a log message, a config value or a string in code. It removes comments as it goes, because a -- comment would otherwise swallow the rest of the query once the line breaks are gone.

Formatting every query the same way before it goes into version control keeps code reviews about logic rather than spacing: a changed condition shows up as one changed line in the diff instead of a rewrapped paragraph. The formatter runs entirely in your browser, so production queries and table names are not sent anywhere.