🗄️ 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
- String literals are rewritten too. The matcher cannot see
quotes, so
note = 'order by date'becomes an ORDER BY on its own line, inside the string. Check any query with words like in, is, set or values in its data. - Every comma breaks. That includes commas inside
COALESCE(a, b)andIN (1, 2, 3), which end up spread over several lines. - Only these keywords are known. WITH, CASE and OVER pass through untouched, in whatever case you typed.
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.