Skip to main content
Alona Tool – Free Online Tools

SQL Formatter

Popular Runs in Your Browser

Format complex SQL queries across PostgreSQL, MySQL, SQLite, and BigQuery. Capitalizes keywords (SELECT, FROM, WHERE, JOIN) and indents subqueries.

Browser-based: this tool works on your device and does not send your input to an Alona Tool server. See the Privacy Policy for details.
Fast Processing

Loading SQL Formatter… This tool is an interactive page and needs JavaScript enabled in your browser.

Example Usage & Test Cases

One-line query
Input Scenario:
select id, name from users where active = 1 order by created_at desc
Generated Result:
SELECT id, name FROM users WHERE active = 1 ORDER BY created_at DESC

How It Works

1

Tokenizes SQL clauses and sub-clauses, converts standard SQL keywords to uppercase, and indents nested joins and conditions.

Frequently Asked Questions

Standard ANSI SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, and Oracle.

Related Tools

Standard SQL Query Formatter and Beautifier

Make complex database queries, multi-table joins, and nested subqueries immediately legible.

A query that arrives as one long line is hard to review. Maybe it came out of an ORM log, a monitoring alert, or a colleague's chat message, and you need to see where the joins and filters sit before you can reason about it. Others use the page before committing a migration script, so that the SELECT, FROM and WHERE clauses each start on their own line and a diff shows only real changes. It also helps when you are teaching someone SQL and want example statements laid out consistently, without hand-editing every line break.

Paste or type your statement into the box labelled Raw SQL Query. The Clean Formatted SQL box on the right updates as you type, so there is nothing to wait for, though the Format & Beautify SQL button above re-runs the formatter if you want to be sure. When the output looks right, press Copy SQL and paste it into your editor or ticket. The sample query on the page is a good way to see what happens: keywords turn upper case and each major clause moves to a new line.

Know what this formatter does and does not do. It collapses every run of whitespace into a single space, upper-cases a fixed list of common keywords, and starts a new line before clauses such as SELECT, FROM, WHERE, the JOIN variants, GROUP BY, ORDER BY, HAVING and LIMIT. It does not indent, it does not break AND or OR conditions onto separate lines, and it does not parse the query. That means a word like count inside a quoted string can also change case, so check literals before running the result.

Here is a small before and after. The input select id,name from users where active=1 order by name becomes four lines: SELECT id,name, then FROM users, then WHERE active=1, then ORDER BY name. The meaning is identical, only the layout changed. Notice that the commas in the column list were left alone, so if you prefer one column per line you will need to split them by hand. Always test formatted SQL against a development database first, because dialect-specific syntax is passed through untouched and never validated.

Key Highlights:

  • Uppercase keyword transformation
  • Clause level indentation
  • Preserves quoted string literals