Skip to content

SQL Formatter

Break a query onto its clauses and upper-case the keywords, without touching identifiers or string literals.

Input

Output

Readable without being rewritten

Each clause — SELECT, FROM, WHERE, JOIN, GROUP BY — starts a line, and the AND/OR conditions under a WHERE are indented beneath it. That is enough to make a query pasted out of a log readable.

Keywords are upper-cased; identifiers, aliases and string literals are left exactly as written. A table called `select_log` stays lower-case, and a literal containing the word FROM is not touched.

Frequently asked questions

Which SQL dialect does it assume?

None in particular. It recognises the clause keywords common to every dialect and leaves everything else alone, so vendor-specific syntax passes through unchanged rather than being mangled.

Will it change my query?

Only whitespace and the case of recognised keywords. The token stream is otherwise identical, so the query runs exactly as before.

Is my query sent anywhere?

No. Queries routinely contain table names, column names and literal values from production; formatting happens entirely in the page.

Related tools