SQL Formatter Online

Beautify or minify SQL queries instantly in your browser.

Indent:
INPUT0 chars
OUTPUT

When a SQL formatter is the right tool

SQL often arrives as one long line, or with mixed case from several tools. A formatter is for a first tidy-up: uppercase a set of keywords, put major clauses on their own lines, or squash a script into a single line. The output updates as you type. This is useful for a quick look, not as a substitute for a parser-based formatter in an IDE.

The rules do not understand string literals, comments, or dialects. If you need to compare two versions, use SQL Diff — and be careful about formatting both sides with this page first, because a keyword inside a quote can change.

Use cases

Reading a minified SELECT

A query copied from a log is easier to scan when SELECT, FROM, WHERE, and GROUP BY each start a line. Load Sample pastes a short report query with a left join, a HAVING clause, and a limit if you want to try that first.

Uppercasing keywords for a review

Some style guides want reserved words in uppercase. Beautify does that for the words on its list. Check string literals afterward, especially if a value is itself a word such as from, join, or table.

Compacting a script

Minify removes -- and /* */ comments and collapses whitespace, which is useful when you want a single-line fixture. Do not minify if those comment markers might appear inside a string.

How formatting works

Beautify first turns all whitespace, including newlines, into single spaces. It then uppercases words from a fixed list and inserts a line break before each major clause. Continuation lines are indented (4 spaces by default, or 2). Minify only strips comments and whitespace; it does not change case. Empty input leaves the output empty. You can copy the result when it is present.

Example — clauses start new lines, keywords are uppercased
select u.id, u.name from users u where u.status = 'active'

SELECT u.id, u.name
FROM users u
WHERE u.status = 'active'

The columns stay on the SELECT line. FROM and WHERE each start a line. That is the usual shape for a simple query.

Example — LEFT JOIN is split by a later JOIN rule
SELECT u.id
FROM users u
LEFT JOIN orders o ON u.id = o.user_id

SELECT u.id
FROM users u
    LEFT
JOIN orders o ON u.id = o.user_id

After Beautify, LEFT and JOIN can sit on two lines. If you need a conventional LEFT JOIN, join those lines back together, or format the query in a tool that parses SQL.

Example — a keyword inside a string can be rewritten
WHERE name = 'from'

WHERE name = '
FROM'

The value from is uppercased and then treated as a clause name, which breaks the quoted string. Always read the output around literals after formatting.

What this tool does not do

It does not parse SQL, preserve literals or comments during Beautify, keep LEFT JOIN on one line, or offer a dialect option. Nothing is sent to a server. For a line comparison of two scripts, use SQL Diff.

How to use SQL Formatter

  1. Paste your SQL into the input pane. The output updates as you type.
  2. Choose Beautify to indent and uppercase keywords, or Minify to compact the text. In Beautify mode, pick 2- or 4-space indent (4 is the default).
  3. Read the output for split joins and rewritten strings, then copy it if it looks right. Use Load Sample to try a short query, or Clear to start over.

Frequently asked questions

Does this page parse SQL or understand a dialect?

No. Beautify and Minify are text rewrites. There is no parser, no dialect setting, and no check that the statement is valid. Keywords are matched as words in a fixed list that mixes common SELECT, INSERT, UPDATE, DELETE, and CREATE clauses, including a few product-specific names such as AUTO_INCREMENT and SERIAL.

What does Beautify actually do?

It first collapses all whitespace to single spaces, then uppercases the keywords in that list, then inserts a line break before major clauses such as SELECT, FROM, WHERE, GROUP BY, and JOIN. Lines that start with one of those clauses stay at the left margin; other lines are indented. The default indent is 4 spaces; 2 is also available. Column lists on a SELECT line are not split onto separate lines.

Why does LEFT JOIN come out as LEFT and JOIN on two lines?

The formatter inserts a break for LEFT JOIN and later also for the shorter word JOIN, which splits the already-rewritten clause. The result is a LEFT line (often indented) and a JOIN line. That is a limitation of the text rules, not a meaning in SQL. You may want to join those two lines back together after formatting.

Will keywords inside string literals or comments be changed?

Yes, they can be. The keyword list is applied to the whole text, including quotes and comments. A value such as 'from' can be uppercased to 'FROM' and then treated as a clause break, which splits the string across lines. Line comments (--) and block comments are also not parsed during Beautify, so words in a comment can be uppercased or moved.

What does Minify change?

It strips -- line comments and /* */ block comments, then collapses remaining whitespace to a single line. It does not uppercase keywords. String literals are not parsed, so a comment-like sequence inside a string could be removed if it matches those patterns.

Is my SQL sent to a server?

No. Formatting runs in your browser as you type. Closing the tab discards what you pasted. Do not paste scripts that contain secrets or personal data if you would not be comfortable with them sitting in memory on this device.

Is there a file size limit?

There is no server-imposed limit, because nothing is uploaded. A few thousand lines is comfortable. A large dump can make the tab feel slow; in that case, format a smaller excerpt or use a local tool.

Related tools and guides

References

  • A real SQL formatter or pretty-printer in your database client or an editor plugin will parse statements and leave string literals and comments alone. Use one of those when this page’s keyword rules would rewrite a value or split a JOIN.
  • For a comparison of two scripts, SQL Diff is the better starting point than formatting each file by eye.