HTML Formatter
Beautify and indent HTML markup.
OpenSplit a long single-line query at its keywords so SELECT, FROM, JOIN and WHERE are easy to scan.
Drop in a logged or hand-written SQL statement of any length.
Each known keyword is uppercased and moved to a new line.
AND and OR lines are indented under the WHERE clause.
Copy the result or download it as query.sql.
An ORM logs the query it generated as a single 900-character line and you need to see which join is producing duplicate rows. Breaking the statement apart at its keywords is usually enough to spot the problem.
The formatter first collapses all whitespace, then starts a new line before each recognized SQL keyword and converts it to uppercase. The list covers clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET), join keywords, INSERT, UPDATE, DELETE, CREATE, ALTER and DROP, plus words like AS, IN, NOT, NULL, LIKE, BETWEEN, CASE, WHEN, THEN, ELSE, END, ASC and DESC. Lines that begin with AND or OR are indented two spaces under their WHERE. Output updates as you type, and Download saves query.sql.
The keyword rule is applied everywhere, which makes it aggressive. LEFT and JOIN land on separate lines, IS NOT NULL is split in three, and a keyword inside a quoted string (say 'Order by phone') is also broken out and uppercased. Use the result for reading and code review rather than pasting it straight into production code. If you are writing a fresh statement, the visual SQL query builder is a better starting point, and spreadsheet rows can become INSERT statements with CSV to SQL. Browse the other code utilities for related formatters.
Queries are rewritten with a few regular expressions in your browser, so table names and literal values copied from production logs are not sent to a server.
Keyboard shortcut
Answers for this tool. For site-wide help, open the FAQ hub.
It does not parse any dialect. It matches a fixed list of common keywords, so SELECT, INSERT, UPDATE and DDL statements from MySQL, PostgreSQL, SQL Server or SQLite all get the same treatment. Dialect-specific words such as RETURNING or QUALIFY stay inline.
LEFT, RIGHT, INNER, OUTER and JOIN are separate entries in the keyword list, and each one gets its own line break. Join them back by hand if you paste the result into source code.
It can. Whitespace inside quotes is collapsed, and keywords that appear inside strings are uppercased and moved to a new line. Compare literals against the original before running the formatted query.