SQL

SQL Formatter query

Add line breaks and indentation to a SQL query so SELECT, JOIN, and WHERE clauses become readable.

indent
INPUTsql
0 lines 0 chars
1
OUTPUTformatted sql
0 lines 0 chars
1
Tool Guide

What this tool does

Queries pulled from an application log or generated by an ORM usually arrive as one long line. That is fine for a short statement, but once several joins, subqueries, and conditions are involved, a single-line query is very hard to reason about.

This tool splits the statement at major clauses such as SELECT, FROM, WHERE, JOIN, ON, GROUP BY, HAVING, ORDER BY, and LIMIT, and indents the result. With each clause on its own line it becomes much faster to see which tables are joined, how many conditions apply, and where grouping and sorting happen.

Formatting only adjusts whitespace and line breaks; it never changes the meaning of the query. Nothing is executed and no database connection is made, since all processing happens in the browser.

When to use it

Use it to analyse a long statement from a slow query log, to see what SQL an ORM actually produces, to read a colleague query during code review, or to tidy a statement before attaching it to a ticket.

Input and output examples

Input select u.id,u.name from users u join orders o on o.user_id=u.id where u.active=1 order by u.id desc
Output SELECT u.id, u.name FROM users u JOIN orders o ON o.user_id = u.id WHERE u.active = 1 ORDER BY u.id DESC

Clause-per-line layout makes the join and filter obvious.

Notes and limitations

This is not a syntax checker: a formatted query is not necessarily an executable one. SQL dialects differ, so product-specific syntax such as optimizer hints, extended window function clauses, or stored procedure bodies may not be laid out as expected. String literals containing words that look like SQL keywords can also pick up awkward line breaks, so review the output.

Frequently asked questions

Is the query executed?

No. There is no database connection; only the text is rearranged.

Does it detect syntax errors?

No. The formatter splits on keywords, so whether a statement runs must be verified against the actual database.

Copied