Developer

SQL formatter

Paste a query and the tool puts each major clause on its own line, uppercases the keywords and leaves quoted strings exactly as they were.

Runs locally in your browser

How it works

Quoted text is protected first: single-quoted strings, double-quoted identifiers and backticked names are swapped for placeholders so nothing inside them can be altered. Runs of whitespace then collapse to a single space, and a line break is inserted before each major clause: FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, UNION, VALUES, SET and the JOIN forms. Finally the known keywords are uppercased, using word boundaries so a column called selected is not turned into SELECTed. The placeholders are restored at the end. Conditions joined by AND or OR stay on the same line to keep the statement readable. The input is capped at 50,000 characters.

Worked example

For select id, name from users where active = 1 order by name limit 10; the output is SELECT id, name on the first line, then FROM users, then WHERE active = 1, then ORDER BY name, then LIMIT 10;. The keywords become uppercase and each clause starts a new line, while the column names keep their lower-case spelling.

Questions and answers

Everything runs in your browser: your text, file or value is never uploaded anywhere.