SQL Formatter

Lays out a query with lines and indents, checks it against the source, and warns about UPDATEs without WHERE, string concatenation and passwords in the text.

The query is not sent anywhere: parsing, formatting, and validation all run in the browser. You can paste queries from logs and source code as is.

The query is split across lines: keywords start a line, fields and conditions move to an indent, joins and conditions after AND and OR each get their own place, and subqueries in parentheses unfold into an indented block. Several queries in a row are separated by a blank line.

The reverse button squeezes the query into a single line, which is handy when you paste it into code or a ticket.

The result is checked against the source

Formatting changes only spaces, line breaks, and the case of keywords. The query can then be parsed again and the token stream compared with the original: the two must match exactly. If anything differs, the tool says so directly instead of showing a ready-made result.

Dangerous spots in a query

Parsing works on the same token tree, so strings and comments are never taken for code. The tool flags:

  • DELETE and UPDATE without a condition, including a placeholder condition like WHERE 1 = 1 that was meant to be filled in later and forgotten;
  • concatenating a string with a value: this is how queries are built by substitution, and a value with a quote inside changes its meaning entirely;
  • passwords, tokens, phone numbers, email addresses, and card numbers in plain query text. The values themselves are never shown, or the report would become a leak of its own;
  • an unclosed quote or comment, and mismatched parentheses;
  • Latin letters inside Russian names: "c", "o", "e", "a" exist in both keyboard layouts, they look identical, but the database will not find such a name;
  • AND and OR in the same condition without parentheses, a row limit without sorting, and NOT IN with a subquery.

The query stays local

Queries often contain passwords, phone numbers, and addresses of real people. Parsing, formatting, and the comparison all run on your side, and nothing is sent anywhere.

Rate this tool

Help us get better

Other tools