SQL Formatter
Format sql data you provide.
About SQL Formatter
Queries copied from application logs, ORM debug output or a teammate's chat message often arrive on one line. Breaking them at the main clauses makes it easier to see the filter conditions, joins and ordering before you run or review them. This is a quick readability aid for analysts and developers.
How it works
The tool first collapses all whitespace into single spaces. Then it starts a new line before these keywords when a space follows them: SELECT, FROM, WHERE, AND, OR, JOIN, LEFT JOIN, RIGHT JOIN, GROUP BY, ORDER BY, LIMIT, INSERT INTO, VALUES, UPDATE, SET and DELETE FROM. Keywords keep their original case, and no indentation is added. ON, HAVING and subqueries get no special handling. The keyword match does not check word boundaries, so a column like color or brand gets split before its last letters. The output can be saved as query.sql.
How to use SQL Formatter
- Enter the text or data in the format shown in the text box above (Paste SQL).
- Select “Run tool” and check the result before copying or downloading it.
Worked example
Input: select id, name from users where active = 1 and age > 30 order by name limit 10. Output, six lines: select id, name / from users / where active = 1 / and age > 30 / order by name / limit 10. Each clause starts a new line, and the lowercase keywords stay lowercase.
Tips for a better result
- Scan the output for identifiers ending in or, and, set or from, such as vendor or offset. A stray line break there is a formatting artifact, not a change to your query.
- Multiple spaces inside string literals are collapsed too. Do not paste the formatted result back if exact spacing inside quoted values matters.
- For deeply nested subqueries or CTEs, use a dialect-aware formatter in your database client. This tool only breaks lines at the main keywords.
Frequently asked questions
Does it uppercase keywords?
No. Each keyword keeps the case you typed. If you want consistent uppercase style, change the keywords in your editor after formatting.
Why was my column name split across two lines?
The keyword search does not require a word boundary before the keyword. In a column like color followed by a space, the trailing or is treated as the OR keyword. The query text is otherwise unchanged, but rejoin that line before running it.
Does it validate or run my SQL?
No. It only rearranges whitespace in your browser. It never connects to a database or checks syntax, so a query with errors is formatted without any warning.
What to check
A formatted or parsed result is not proof that code is secure, correct or production-ready. Never paste production secrets.
Read the Privacy Policy for information about local processing, connected services and advertising.