Back to Utilities
FORMATTER

SQL Formatter

Format and beautify SQL queries with customizable indentation and keyword casing.

Accepts: .sql
0chars
0lines
0words

User Guide

Overview

The SQL Formatter is a powerful tool for beautifying and organizing SQL queries. It automatically adds proper indentation, line breaks and consistent keyword casing to make your SQL more readable and maintainable.

When to Use SQL Formatter

  • Cleanup Minified Queries: Transform one-line queries into readable, structured SQL
  • Code Reviews: Format queries before sharing with team members
  • Documentation: Create clean, professional SQL examples for docs (similar to our JSON Formatter for JSON)
  • Debugging: Make complex queries easier to understand and troubleshoot
  • Learning: Study well-formatted SQL to understand query structure
  • Standardization: Enforce consistent SQL style across projects

How to Use

  1. 1. Set Options: Choose your preferred indentation (2, 4 or 8 spaces) and keyword casing
  2. 2. Paste SQL: Enter or paste your SQL query in the input area
  3. 3. Format: Click "Format SQL" to beautify your query
  4. 4. Copy: Use the "Copy" button to copy the formatted SQL to your clipboard
  5. 5. Try Example: Click "Load Example" to see a sample query

Examples

Basic SELECT Query

Before:

select id,name,email from users where status='active' order by created_at desc

After:

SELECT id,
  name,
  email
FROM users
WHERE status='active'
ORDER BY created_at DESC

JOIN Query

Before:

select u.name,o.total from users u inner join orders o on u.id=o.user_id where o.status='completed'

After:

SELECT u.name,
  o.total
FROM users u
INNER JOIN orders o
  ON u.id=o.user_id
WHERE o.status='completed'

Complex Aggregation

Before:

select category,count(*) as total,avg(price) as avg_price from products where active=true group by category having count(*)>5 order by total desc

After:

SELECT category,
  count(*) AS total,
  avg(price) AS avg_price
FROM products
WHERE active=true
GROUP BY category
HAVING count(*)>5
ORDER BY total DESC

INSERT Statement

Before:

insert into users (name,email,status) values ('John Doe','john@example.com','active')

After:

INSERT INTO users (name,
  email,
  status)
VALUES
  ('John Doe',
  'john@example.com',
  'active')

Use Cases

Database Development

Format queries during development, maintain consistent SQL style and make code reviews more efficient.

Data Analysis

Clean up ad-hoc queries, share formatted SQL with team members and document data analysis processes.

Learning SQL

Study well-formatted examples, understand query structure and develop good SQL formatting habits.

Legacy Code

Beautify old queries, improve readability of inherited code and prepare SQL for refactoring.

Frequently Asked Questions

Related Utilities