SQL Formatter

Converter

Format and indent SQL queries with a regex-based prettifier for SELECT, INSERT and UPDATE statements to keep database code clean and readable.

Input → Output
12 lines · 221 chars
SQLInput
SQLOutput

About SQL Formatter

SQL produced by an ORM or grabbed from logs is often crammed onto one long line, with keywords, columns, and subqueries all jammed together and hard to read. This tool formats SQL locally in your browser — wrapping, indenting, and aligning keywords so SELECT, JOIN, and WHERE structures stand out for review and tuning. Statements are parsed on your machine, so queries with real table names are never uploaded. Tip: Bookmark this tool for quick access whenever you need format conversion. All processing happens locally in your browser — no data upload, so feel free to paste sensitive content.

How to Use

  1. Open the SQL Formatter tool page
  2. Enter or paste your data into the input area
  3. View the real-time results and use the copy button to get the output

Use Cases

  • Beautify log SQL — Format a one-line slow query from logs to see its JOIN and subquery structure.
  • Review ORM output — Format ORM-generated SQL to confirm it produces the query you expected.
  • Prep for tuning — Lay out a complex query clearly to spot redundant subqueries or missing index conditions.
  • Unify team style — Normalize indentation across colleagues' varied SQL for easier code review.
  • Teaching — Expand nested queries into layers to explain execution logic to newcomers.
  • Format embedded SQL — Extract inline SQL from application code and format it to review the query logic before debugging.
  • Align migration scripts — Reformat multiple SQL migration files consistently to maintain a uniform style across the codebase.

FAQ

Does it change the query result?

No. Formatting only adjusts whitespace, line breaks, and indentation; keywords, columns, and logic are untouched, so semantics and results stay identical.

Which SQL dialects are supported?

It formats standard SQL and common dialects like MySQL and PostgreSQL well. A few vendor-specific syntaxes may not be fully recognized but usually still format acceptably.

Are keywords uppercased?

It typically normalizes keywords to uppercase for readability, while column names and values keep their original case.

Can it minify to one line?

This tool focuses on pretty-printing. To collapse multi-line SQL for embedding, remove the line breaks manually or use a compact mode where available.

Are comments preserved?

Single-line (--) and multi-line (/* */) comments are generally kept and placed sensibly, though comments in odd positions may be re-wrapped — verify quickly after formatting.

Any browser compatibility requirements?

This tool works in all modern browsers (Chrome, Firefox, Edge, Safari). No plugins or extensions required.

Can I use it offline?

After initial load, most features work offline. The core logic runs entirely in your browser with no network dependency.

Advertisement

Comments

No comments yet. Be the first!

Comments are stored locally in your browser. Configure Giscus for cloud-based comments.