SQL Formatter
Reformat SQL by inserting a line break before each major keyword — a broad keyword list covering joins, clauses, and DDL statements.
- 1Paste your SQL query
- 2Click Convert
- 3Copy the reformatted query with keyword line breaks
What this SQL formatter does
Long SQL written on one line is hard to read. This tool inserts a line break before each major SQL keyword, so a query is laid out as separate clauses. For example select name, total from orders where total > 100 order by total becomes one line for the select list, one for from, one for where and one for order by.
Keywords that start a new line
The formatter breaks before SELECT, FROM, WHERE, JOIN (with LEFT, RIGHT, INNER and OUTER), ON, AND, OR, NOT, IN, LIKE, BETWEEN, ORDER BY, GROUP BY, HAVING, LIMIT, OFFSET, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, CREATE TABLE, ALTER TABLE, DROP TABLE, UNION, UNION ALL, AS, DISTINCT and the aggregate names COUNT, SUM, AVG, MAX and MIN. Matching is case-insensitive, and the keyword's original capitalisation is kept.
What it is good for
- Making a query from a log file or ORM debug output readable.
- Getting an overview of the clauses and joins in a query someone else wrote.
- Preparing a query for a code review, ticket or document.
What it does not do
- No indentation of nested queries. Subqueries are split into lines but not indented under their parent.
- Aggressive line breaking. Because AND, OR, IN, AS and function names such as COUNT also trigger breaks, simple expressions can be split across several lines.
- Keywords inside strings. A string literal such as
'this and that'contains the word AND and may be broken. Check string values after formatting. - No dialect awareness. It does not validate syntax and treats MySQL, PostgreSQL, SQL Server and Oracle queries the same way.
- It never changes meaning on purpose. Only whitespace is added, but always run the formatted query in a safe environment before relying on it.
Habits that make SQL easier to read
- Put each selected column on its own line when there are more than three or four.
- Write join conditions directly under the join they belong to.
- Use meaningful table aliases (
ofor orders,cfor customers) rather thant1,t2. - Name columns explicitly instead of using
SELECT *in production queries.
Never paste queries that contain real customer data or credentials into any online tool unless you trust it; this one runs locally in your browser, but get into the habit of using placeholder values. Related: the JSON formatter for API payloads.
Related Tools
JSON Formatter
Pretty-print JSON with real 2-space indentation using the browser's native JSON parser — shows the exact parse error if your JSON is invalid.
JSON Minifier
Compress JSON to its smallest valid form by removing all whitespace, using the native JSON parser.
XML Formatter
Reformat XML with proper nested indentation based on tag depth — a lightweight tag-based indenter, not a full XML parser.