SQL Formatter

Beautify or minify SQL queries — format keywords and clauses onto clean lines, in your browser.

Suggested tools

SQL Escape / Unescape

Double single quotes for SQL string literals, or undo it.

SQL
Open Tool

JSON Formatter

Beautify, minify and validate JSON instantly in your browser.

JSON
Open Tool

XML Formatter

Beautify, minify and validate XML instantly in your browser.

XML
Open Tool

YAML Formatter

Re-indent YAML and check it for syntax errors, with line numbers.

YAML
Open Tool

JSON5 Formatter

Format JSON5 with comments, unquoted keys and trailing commas.

JSON5
Open Tool

HTML Formatter

Indent and tidy HTML, or minify it.

HTML
Open Tool

About SQL Formatter

SQL Formatter makes long queries readable: keywords are uppercased and major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY…) start on their own lines. Minify does the opposite, putting a query on one compact line and removing comments.

String literals and quoted identifiers are never changed, so values like 'Select me' stay exactly as written. It works with the standard SQL used by MySQL, PostgreSQL, SQL Server, SQLite and Oracle. It runs entirely in your browser, so nothing you paste is uploaded.

How to use SQL Formatter

  1. Paste your SQL query.
  2. Press Format or Minify.
  3. Copy the result.

Key features

  • Keywords uppercased, clauses on new lines
  • Minify to a single line
  • String literals and quoted names untouched
  • Works with common SQL dialects

Example

Keywords are uppercased and each clause starts on a new line; the string 'paid' is untouched.

Input
select u.id, u.name, sum(o.total) as spent from users u join orders o on o.user_id = u.id where o.status = 'paid' group by u.id, u.name order by spent desc
Output
SELECT u.id, u.name, sum(o.total) AS spent
FROM users u
JOIN orders o ON o.user_id = u.id
WHERE o.status = 'paid'
GROUP BY u.id, u.name
ORDER BY spent DESC

When to use SQL Formatter

  • Making a long query from logs or an ORM readable before debugging it.
  • Formatting queries consistently for code review.
  • Compacting a query to one line for a config file or a script.

Tips and common problems

  • Formatting never changes string literals such as 'paid' or quoted column names.
  • Minify removes comments, so keep a formatted copy if comments matter.
  • Run the formatted query in your database client to check it — formatting does not validate SQL.

Frequently asked questions

No. Only whitespace and keyword case change; SQL keywords are case-insensitive.