SQL Formatter

Format SQL queries into a more readable structure for development, debugging, review and database work.

Ad space — place your AdSense unit here after approval.
Note: this is a pattern-based formatter. Check string literals, template literals and regular expressions in the output before using it in production.
Your result will appear here.

SQL Formatter online

Format SQL into the classic keyword layout — major clauses on their own lines, keywords uppercased, lists indented — so a one-line query becomes something you can actually read.

Quick answer: Format SQL queries into a more readable structure for development, debugging, review and database work.

How to use this tool

  1. Paste your SQL into the input box.
  2. Click Run Tool. Whitespace collapses, commas open indented list lines, and the main clause keywords are uppercased and given their own lines.
  3. Copy the formatted query from the result panel.

Common uses

Reading a query copied out of application logs, reviewing ORM-generated SQL, preparing a query for a bug report or a colleague, and sanity-checking a long reporting query before running it against production.

How it works

The formatter is keyword-driven: it first collapses all whitespace to single spaces, turns commas into line breaks with a two-space indent (so column and value lists stack vertically), then puts each major keyword — SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, the JOIN family, SET, VALUES, UNION, AND, OR — at the start of its own line in uppercase. It does not parse the query, indent subqueries by depth, or know your dialect; the layout is a consistent convention, not an analysis.

Worked example

The one-liner

select id, name from users where age > 30 and city = 'Oslo' order by name

becomes

SELECT id,
  name
FROM users
WHERE age > 30
AND city = 'Oslo'
ORDER BY name

Each condition gets its own line, which is where most people spot the missing parenthesis or the AND that should be an OR.

Privacy and browser processing

Your SQL is formatted in your browser with JavaScript — it is never uploaded or stored.

Frequently asked questions

Why did text inside my string literal change?

The keyword pass is textual, so a literal containing a word like "and" or "from" (say, WHERE name = 'Fish and Chips') can be uppercased and split across lines. Format queries whose literals avoid bare keywords, or restore the literal afterwards.

Does it indent subqueries and CTEs?

No — there is no depth tracking, so a subquery formats inline within its clause. The main clauses still separate cleanly; for deeply nested analytics SQL, a parser-based formatter in your IDE goes further.

Which SQL dialect is it for?

The keyword list is the common core shared by MySQL, PostgreSQL, SQL Server and SQLite. Dialect-specific syntax passes through unformatted rather than mangled, since only the listed keywords are touched.

Will it catch errors in my query?

No. It makes structure visible — a GROUP BY stranded after ORDER BY stands out — but it executes and validates nothing.

Is my query uploaded?

No. Formatting runs in your browser; your SQL never leaves the page — worth knowing if the query embeds table names or values you would rather keep local.

Related tools

Ad space