Skip to content
FreeRuns in your browser

SQL Formatter

Format SQL queries with consistent keyword casing and indentation so complex joins become readable.

Use the SQL Formatter

Loading tool...

What is the SQL Formatter?

SQL queries generated by ORMs, query logs and monitoring tools often arrive as one enormous line. A SQL formatter breaks the statement into clauses, putting SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY on separate lines, aligning columns and indenting subqueries, so the logic can be reviewed at a glance.

Consistent formatting is more than cosmetics. It makes code review and diffs easier, reveals missing join conditions, and helps you spot accidental cartesian products. Dialects differ slightly (backtick quoting in MySQL, double quotes in PostgreSQL, brackets in SQL Server), so choose the dialect that matches your database for the best result.

When to use the SQL Formatter

Format SQL before you commit a migration, paste a query into a pull request, share a slow query with a database administrator, or document an analytics report. ORMs and query logs emit queries on one line, and reading them in that form hides mistakes such as a missing join condition or a filter on the wrong table alias. Consistent formatting also produces cleaner diffs when someone changes a single clause in a long statement.

How to use the SQL Formatter

  1. Paste your SQL statement or script into the input area.
  2. Select the dialect that matches your database.
  3. Choose the indent size and whether to uppercase keywords.
  4. Press Format and review the structured output.
  5. Copy the query into your editor, migration or documentation.

Examples

Input:

select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id,u.name having count(o.id)>2 order by orders desc limit 10;

Formatted:

SELECT
  u.id,
  u.name,
  COUNT(o.id) AS orders
FROM users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE u.active = 1
GROUP BY u.id, u.name
HAVING COUNT(o.id) > 2
ORDER BY orders DESC
LIMIT 10;

Common errors and tips

  • Formatting never changes query results; it only changes whitespace and keyword case.
  • Always put an explicit ON condition on joins; a missing one is easy to spot once formatted.
  • Never paste production credentials or sensitive literals into any tool you do not control; this tool is local, but habits matter.
  • Use parameterised queries in your application instead of building SQL strings by hand to avoid SQL injection.
  • Comments (-- note) are preserved; make sure they end with a newline when you minify.

Privacy: runs entirely in your browser

Queries often reveal table and column names; formatting happens locally, so your schema is never sent to a server. This tool runs entirely in your browser: nothing you enter is uploaded, stored or logged on our servers, and it keeps working even if you go offline after the page has loaded.

Frequently asked questions

Does formatting change the query result?

No. Only whitespace and keyword capitalisation change, so the execution plan and results are identical.

Which SQL dialects are supported?

Standard SQL plus MySQL, PostgreSQL, SQL Server and SQLite style syntax. Selecting the right dialect improves quoting and keyword handling.

Why uppercase keywords?

It is a widely used convention that visually separates SQL keywords from table and column names, improving readability. It is optional.

Can it format multiple statements?

Yes. Separate statements with semicolons and each will be formatted in turn.

Ratings & reviews

–

0 reviews

5 star
0 reviews (0%)
4 star
0 reviews (0%)
3 star
0 reviews (0%)
2 star
0 reviews (0%)
1 star
0 reviews (0%)

No reviews yet — be the first to share your experience.

Write a review

Reviews are moderated before they appear.

Your rating *

Photos or videos (optional)

Drag files here or

JPG, PNG, WebP, GIF up to 5 MB. MP4 or WebM up to 25 MB.

  • Featured

    Beautify, minify and validate JSON instantly, with exact line and column for every syntax error.

    Use tool
  • Featured

    Encode text to Base64 or decode Base64 back to readable UTF-8, including URL-safe Base64.

    Use tool
  • Featured

    Generate random v4 and time-ordered v7 UUIDs in bulk, with one-click copy and format options.

    Use tool
  • Regex Tester

    Developer

    Featured

    Test JavaScript regular expressions live, with highlighted matches, capture groups and flag toggles.

    Use tool
  • JWT Decoder

    Developer

    Featured

    Decode JSON Web Tokens to inspect the header, payload and expiry, all without sending the token anywhere.

    Use tool
  • Featured

    Convert Unix timestamps to readable dates and back, in UTC or your local timezone, in seconds or milliseconds.

    Use tool