SQL Formatter & Beautifier

Paste one SELECT, INSERT, UPDATE, or DELETE statement and reprint it with each major clause on its own line.

Use this tool

The file is read on this page and is not uploaded.

Result

The result appears in this panel after you run the tool.

About this tool

Beautify and pretty-print mean the same thing here: the statement is broken onto clause lines and indented. The recognized clauses include FROM, WHERE, JOIN, GROUP BY, ORDER BY, SET, VALUES, and LIMIT. The result is still SQL text. Nothing is sent to a database.

Use it to read a query that arrived on one line, or to line up a statement before you paste it into a client you trust. The tool does not know your schema, so it cannot tell you that a column exists. Formatting is not validation against a server.

Tabs use one tab per level. The size applies when the style is spaces. A source longer than 1 MB is refused. The statement stays in this browser.

How to use it

  1. Paste one statement, or choose a local file. The file is read on this page and is not uploaded.
  2. Choose an indent, then Format SQL. Ctrl+Enter or Cmd+Enter does the same thing from the box.
  3. Copy or download the reprint. A statement outside the supported subset is reported instead of being guessed.

Limitations

Four statement kinds, broken onto clauses

Whitespace is flattened, then a short keyword list is lifted

Four statement shapes get clause breaks. The paste is trimmed and every run of whitespace becomes a single space. The result has to start with SELECT, INSERT, UPDATE, or DELETE, compared without caring about case. Anything else is refused. A semicolon that appears anywhere except as the final character is refused, which keeps a second statement out of this pass. The formatter is not talking to a database, and it is not checking that tables or columns exist.

After that flatten, a fixed list of keywords is rewritten in uppercase and moved onto a following line: SELECT, FROM, WHERE, GROUP BY, ORDER BY, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, INNER JOIN, LEFT JOIN, RIGHT JOIN, and LIMIT. The first line stays at the left margin. Each later line receives one indent, which is two spaces, four spaces, or a tab. There is no deeper indent for a subquery, because this is not a parse tree. The keyword scan runs on the flattened text.

Quoted text is not protected from the keyword scan

A keyword that happens to sit inside a string literal can be moved, because the scan does not track quotes. A bare JOIN that is not written as INNER JOIN, LEFT JOIN, or RIGHT JOIN is not in the list, so it may stay mid-line. WITH, UNION, and procedural blocks are outside the four opening words, so a file that starts with them is rejected even if the rest would have been readable. Comments are not stripped specially. They are just more text in the flatten, and a comment marker can end up beside a keyword.

Readability for one statement, nothing more

The page will not invent a missing FROM, and it will not decide whether a name is a column. Case of identifiers is left as it was after the whitespace flatten, except for the keywords in the list, which become uppercase. If you wanted every space removed and line comments deleted, that is the SQL minifier, which does not do these clause breaks. Use this formatter for a single SELECT, INSERT, UPDATE, or DELETE whose clauses you want stacked.

Privacy

Your SQL is processed in your browser and is not uploaded to UtilChain. File names, source text, and results are not sent to analytics.