🗄️ SQL Formatter

Paste a SQL query to reformat it with uppercase keywords and each major clause on its own line. This is a simple text-based formatter, not a full SQL parser — always review the output.

What the formatter actually does

Four passes of text substitution, no SQL parsing. Whitespace is collapsed to single spaces, 36 keywords are uppercased longest-first so INNER JOIN wins over JOIN, a line break is inserted before 18 clause keywords, and every comma starts a new line. The sample query comes out as:

SELECT id,
name,
email
FROM users
WHERE active = 1
AND created_at > '2024-01-01'
ORDER BY name ASC
LIMIT 50;

Lines are trimmed at the end, so the result is flat - nothing is indented. It is a readability pass for a query pasted out of a log.

Where it will bite

Nothing is executed, and outside quotes nothing changes meaning - but diff the output before pasting it over a working statement.

Frequently asked questions

Does formatting a query change what it returns?

SQL ignores whitespace and keyword case, so a reformatted query normally runs identically. The exception is text inside quotes: if a literal contains a keyword, this tool will rewrite it and the results will differ.

Why is my SELECT list one column per line with no indent?

Every comma is followed by a line break, and the final pass trims leading whitespace from each line. Add your own two-space indent afterwards if your team's style calls for it.

Can it format a CTE or a window function?

Partly. WITH, CASE and OVER are not in the keyword list and stay as typed, while the SELECT and FROM inside them are still broken onto new lines.