JSON & Data

SQL Formatter & Beautifier

Format, indent, and standardize complex SQL queries for PostgreSQL, MySQL, and SQLite.

Runs 100% locally in your browser

What Does the SQL Formatter & Beautifier Do?

The SQL Formatter & Beautifier parses raw or single-line SQL statements and formats major clauses (SELECT, FROM, INNER/LEFT JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT) onto cleanly indented lines.

String literals enclosed in single or double quotes are preserved untouched so embedded text is never corrupted during keyword casing or whitespace normalization.

You can switch between 2-space and 4-space indentation, standardize SQL keywords to UPPERCASE or lowercase, or compact multi-line queries into a single line.

How to Use This Tool

  1. Paste your raw SQL query into the input editor or click 'Load Example'.
  2. Choose Prettify or Compact mode, select 2 or 4 spaces indentation, and toggle UPPERCASE keywords.
  3. Copy the formatted SQL or download it as a .sql file.

Common Engineering Use Cases

  • Formatting long single-line SQL queries captured from ORM debug logs (Prisma, Hibernate, TypeORM, Sequelize).
  • Standardizing SQL style before committing database migration scripts or analytical queries.
  • Compressing multi-line SQL queries into a single line for log search or CLI execution.

Practical Developer Examples

Formatting an Analytical JOIN Query

Major SQL clauses and boolean conditions are aligned on dedicated lines.

Input
select u.id, count(o.id) as orders from users u inner join orders o on o.user_id = u.id where u.active = 1 group by u.id;
Output
SELECT u.id,
  COUNT(o.id) AS orders
FROM users u
INNER JOIN orders o ON o.user_id = u.id
WHERE u.active = 1
GROUP BY u.id;

Common Mistakes & Pitfalls to Avoid

  • Using naive regex replacements on SQL queries without protecting quoted string literals first, which accidentally uppercases words like 'select' or 'and' inside user data strings.

Frequently Asked Questions

Are my database queries or schema names uploaded anywhere?

No. SQL formatting runs 100% locally in your browser memory. Proprietary table names and query filters never leave your machine.