SQL Query Beautifier

Format SQL with consistent keyword case and line breaks, leaving string literals untouched.

Why use this tool?

Format SQL queries with consistent keyword case and one clause per line so they're easy to read and review. String literals and comments are never changed.

How to use it

  1. Paste your SQL.
  2. Click Format Query.
  3. Copy the formatted SQL.

What the formatter changes, and what it doesn't

It puts SQL keywords such as SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY in capital letters, puts each main clause keyword on its own line and indents what belongs to it underneath, so the structure of a query is visible at a glance. Table names, column names and values keep their original spelling.

String literals and comments are never changed. The query is split into pieces first, and anything inside quotes, such as 'New York' or 'select', is left exactly as written. Formatting only changes spacing and keyword case, so the query does exactly the same thing afterwards.

Worked example

Input on one line: select id, name from users u join orders o on o.user_id = u.id where o.total > 100 and u.city = 'Lyon' order by o.total desc. After formatting, each clause keyword (SELECT, FROM, JOIN, WHERE, ORDER BY) sits on its own line with its contents indented underneath: the two columns id and name on separate lines under SELECT, users u under FROM, orders o and ON o.user_id = u.id under JOIN, o.total > 100 and AND u.city = 'Lyon' under WHERE, and o.total DESC under ORDER BY. The city value 'Lyon' keeps its original case because it's inside quotes.

Why formatting helps

Queries copied from logs, ORMs or reporting tools usually arrive as one long line. Breaking them into clauses makes it much easier to see which tables are joined, what the filters are and where a condition is missing. Consistent formatting also makes changes easier to review, because a diff shows the clause that changed rather than one enormous edited line.

Many teams agree on a style, such as capital keywords and one clause per line, so that everyone's queries look the same in code review.

Limits

The formatter doesn't check that a query is valid or will run; it formats what you give it. Database systems such as PostgreSQL, MySQL, SQL Server and SQLite each have some keywords and syntax of their own, so unusual dialect-specific statements may be formatted less neatly, but their meaning is never changed.

Avoid pasting queries that contain real passwords, API keys or personal data into any online tool. Formatting runs in your browser here, but it's a good habit everywhere.

Frequently asked questions

Will formatting change what my query does?

No. Only spacing, line breaks and keyword case change. Values in quotes and comments are left exactly as they were.

Does it check my SQL for errors?

No. It formats the text you paste but doesn't run or validate it. Your database will report syntax errors when you execute the query.

Why are keywords in capitals?

It's a long-standing convention that makes keywords stand out from table and column names. SQL itself isn't case-sensitive for keywords, so it works either way.