DEVELOPER TOOL

SQL Formatter

Format SQL queries for readability.

About SQL Formatter

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.

How to use SQL Formatter

  1. Click into the large text box and paste the SQL you want to tidy. You can include more than one statement.
  2. Press the Format button to run the formatter on whatever is currently in the box.
  3. Read the formatted query in the result block below. Clauses begin on new lines and nested parts are indented.
  4. If an error message appears in the result block instead, look for unbalanced quotes or parentheses, or unsupported syntax, correct the input, and press Format again.

When this tool helps

Reading a logged query

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.

Preparing a query for code review

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.

Untangling nested subqueries

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.

Cleaning up generated SQL

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.

Tips for better results

  • Remove any non-SQL text first, such as log timestamps or a surrounding string literal from your code. Extra characters around the query are the most common reason formatting fails.
  • Replace placeholders you cannot avoid with simple values only if the formatter rejects them. Many parameter styles are accepted, but some syntax is vendor-specific.
  • After formatting, scan the WHERE clause and join conditions. Once each condition has its own line, missing parentheses around OR logic are much easier to spot.
  • If you format a query that contains real customer data or secrets in literals, replace them before sharing the output, since formatting does not remove anything.

Good to know

  • Only the standard SQL dialect is used. Vendor-specific syntax from systems like PostgreSQL, SQL Server, or Oracle may format imperfectly or be rejected.
  • The tool does not run, validate, or optimize queries. It does not know your schema, so a nicely formatted query can still be wrong.
  • There are no options for indentation width, keyword case, or line length, and no copy button, so select the result text yourself.

Privacy and your data

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.

SQL Formatter FAQ

Does the formatter change what my query does?

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.

Will it execute my SQL?

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.

Which SQL dialects are supported?

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.

Why do I see an error instead of formatted SQL?

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.

Can I choose uppercase keywords or tab indentation?

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.

Can I format several statements at once?

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.

Browse all ELDOSA tools →