Free developer tool

SQL Formatter

Paste your SQL and press Format. Keywords become uppercase, and each clause starts on its own line so long queries are easy to read.

Report a problem or suggest a fix for this tool

What is sql formatter?

Long SQL on a single line is hard to read and review. This formatter puts each clause on its own line and capitalizes the keywords.

It works with common SQL dialects. Strings and quoted names are left alone.

How to use the sql formatter

  1. Paste your query.
  2. Press Format SQL.
  3. Copy the formatted query.

How the sql formatter works

The formatter finds major clauses such as SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT outside of quotes, starts a new line for each, and puts select columns and AND or OR conditions on indented lines.

Worked example

The one line query that selects users with an order count becomes a block with SELECT, LEFT JOIN, WHERE, GROUP BY, ORDER BY and LIMIT on separate lines.

Common uses of the sql formatter

  • Code review.
  • Documenting queries.
  • Learning SQL.
  • Cleaning generated SQL.
  • Sharing queries with a team.

Tips and common mistakes

Keep table aliases short and clear.

Always test formatted SQL before running it on live data.

Use comments for tricky logic.

Background: what to know before you rely on it

SQL ignores extra spaces and line breaks, so formatting is a human aid. Consistent style across a team speeds up reviews and helps find mistakes in joins and filters.

Private, free and fast

This tool runs in your browser. What you type or choose is not sent to a server and is not saved after you close the page. No sign in is needed. It is free to use as often as you like. See more in all developer tools, or browse the full list of tools.

Field by field guide

  • SQL query: Type or paste your text here. Use a new line for each entry where the label says so.

Change one field at a time to see how the result responds, and use the worked example above to check that you get the same answer.

Formatting SQL for review

SQL is read by people far more often than it is written. Putting each clause on its own line makes joins, filters and groupings easy to compare.

Practical scenarios

  • Reviewing a long reporting query from a log by placing SELECT, FROM, JOIN, WHERE and GROUP BY on separate lines.
  • Making an ORM generated statement readable before you tune an index.
  • Sharing a query in a ticket so colleagues can comment on single lines.

Common mistakes

  • Expecting the formatter to change results. Only layout and keyword case change.
  • Pasting production data values into a shared document. Replace real values with placeholders.
  • Assuming one dialect fits all. Vendor specific syntax can be laid out differently than your database expects, so always run the query to confirm.

Making SQL easier to maintain

Consistent formatting lets reviewers see structure at a glance. Standard practice is one clause per line, indentation for subqueries and capital keywords.

Expert tips

  • Alias tables with short meaningful names, such as o for orders, and use them to prefix every column.
  • Put each join on its own line with its ON condition beneath it.
  • Avoid SELECT star in production queries. List the columns you need.
  • Comment non obvious filters and keep comments short.
  • Run EXPLAIN on slow queries to see which indexes are used.

A formatter handles layout only. Correctness and performance still depend on your schema, indexes and query logic.

Frequently asked questions

Does it run my SQL?

No. It only changes layout.

Does it support every dialect?

It handles common standard syntax. Unusual vendor features may format differently.

Does it change my results?

No. Keywords and spacing change, not logic.

Is my query uploaded?

No.

Embed this tool on your website

Copy the code below and paste it into your page or blog post. The tool is free to embed, runs in the visitor's browser and needs no account. Please keep the credit link.

Related tools

Results are for information and education. For legal, financial, medical or security decisions, check with a qualified professional. Do not paste live secrets into any website.