SQL Formatter
Format SQL queries for readability.
Format SQL queries for readability.
A query copied from an ORM log, a dashboard, or a colleague's message often arrives as one long line. Paste it into the box and press Format, and the statement is broken into clauses with line breaks and indentation, so SELECT lists, joins, conditions, and subqueries can be read at a glance.
Formatting uses the standard SQL dialect option of an open-source formatting library that runs on this page. It reorganizes whitespace and layout only. It never connects to a database, never runs your statement, and does not check whether the tables or columns exist. A clean layout simply makes mistakes easier for you to see.
Because the dialect is generic, features unique to one database product may not come out perfectly, and unusual syntax may produce an error message in place of the formatted text. For most everyday SELECT, INSERT, UPDATE, and DELETE statements the result is a tidy, consistent layout you can paste back into your editor.
Application logs and slow-query reports usually print SQL on a single line. Formatting it exposes the joins and the WHERE conditions, which helps you spot a missing filter or an accidental cross join.
Before sharing a query in a pull request or ticket, format it so reviewers can follow the logic. Consistent layout also keeps version-control diffs focused on real changes instead of spacing.
A report query with several subqueries and CASE expressions is hard to follow when compressed. Indentation shows which parts belong together and where each parenthesis opens and closes.
Query builders and BI tools output dense statements. Reformatting them gives you something to read, annotate, and adapt by hand when you need to tune performance or move logic elsewhere.
Formatting runs in your browser using a library bundled with the page. The SQL you enter is not sent to a server by this tool.
It should not. The formatter only changes whitespace and line breaks, not the logic. Even so, review the result before you rely on it, particularly with unusual syntax, comments, or vendor-specific features, and compare it with the original if the query is critical.
No. It never connects to a database and nothing is executed. The text is only rearranged for readability. That also means it cannot tell you whether table names, column names, or functions exist, or whether the statement will return the rows you expect.
The tool uses the generic standard SQL setting. Common statements work well, but extensions specific to MySQL, PostgreSQL, SQL Server, or Oracle might not be recognized. If something fails, try formatting a simplified version of the query without the product-specific parts.
The formatter could not read part of the text. Typical causes are an unterminated string, unbalanced parentheses, stray characters from copying, or syntax the standard dialect does not handle. The message names the problem area, so check that part of the input.
Not here. The page runs the formatter with default layout settings and exposes no style controls. If your team has a strict style guide, copy the result into your editor or formatter configuration and apply your preferred rules there.
Yes. Statements separated by semicolons can be pasted together and are laid out one after another. Very large scripts may take a moment on slower devices, and a syntax problem in one statement can stop the whole run, so fix errors and format again.