Quick

SQL Formatter/Beautifier

Paste a query and get it formatted with consistent line breaks, indentation and uppercase keywords.

Advertisement

About this tool

Puts each main clause (SELECT, FROM, each JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, UNION and so on) on its own line, lists the selected columns one per line, and starts each AND or OR in a WHERE or ON condition on a new, indented line. The AND inside BETWEEN … AND … and inside a CASE expression stays where it is. Subqueries are indented one level inside their brackets, and several statements separated by semicolons are each formatted in turn.

The formatter reads the SQL properly rather than just searching the text, so nothing inside quotes is changed: a word like select inside a string keeps its case and spacing, and comments are kept in place. Keyword uppercasing and the indent size can be switched in the options above the result.