SQL

SQL Formatter and Beautifier

Re-prints a query with one clause per line, consistent keyword case and readable indentation.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste your SQL, or drop a .sql file onto the box.
  2. Choose the indentation, keyword case and comma position your team uses.
  3. Select Format, then copy or download the result.

What sql formatter does

A SQL formatter rewrites the whitespace and keyword case of a statement without touching what it does. Clauses move onto their own lines, nested subqueries indent one level, and the joins line up so that you can see at a glance which tables a query actually touches. The parsed statement is identical before and after, so formatting is safe to run on anything you can read.

Formatting is usually the first step in understanding somebody else’s query. A four-hundred-character single line hides an accidental cross join; the same text with one clause per line makes the missing ON condition obvious. String literals and comments are copied through exactly as written, including any SQL-looking text inside them, because rewriting the contents of a literal would change the query’s meaning.

Frequently asked questions

No. Only whitespace and keyword case change, and neither is significant to a SQL parser outside string literals — which are left exactly as written. The statement you get back is the same statement.

None in particular. It works at the token level, so dialect-specific keywords and functions pass through untouched even though it does not recognise them. That also means it will happily format a statement that your database would reject.

No. Formatting happens in your browser using JavaScript on this page. The text never leaves your machine, which matters because queries often carry table names and literal values you would not want to paste into a server-side tool.

Comments are placed on their own line so they cannot accidentally swallow the code that follows them. A line comment that ends up mid-statement after reformatting would comment out the rest of that line.