How to use the SQL formatter
A query written on one long line makes it hard to see where the filter ends and the sort begins. Paste it here and the tool starts a new line at each major keyword and indents by the current parenthesis depth. The keywords that start a new line are SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, the JOIN variants and ON. AND and OR are indented one extra level so the number of conditions is obvious at a glance.
Before anything is rearranged, single-quoted and double-quoted strings and comments are lifted out and put back untouched at the end. A word such as from or and inside a string is therefore never mistaken for a keyword and never uppercased. The number of protected spans is reported above the output.
This is indentation-level tidying, not a full SQL parser. The query is not checked for validity, and subqueries are indented only by parenthesis depth. Turning on the comma option breaks after every comma, including commas between function arguments, not just items in a SELECT list. Input is accepted up to 100,000 characters and everything runs in your browser.
Frequently asked questions
No. Quoted strings and comments are lifted out before formatting and restored exactly as they were. Words inside them are never split onto new lines or uppercased.
No. It only rearranges the text for readability and performs no syntax checking. Whether the query actually runs has to be confirmed against your database.