SQL Query Formatter

Format database queries with cleaner indentation, keyword capitalization, and clause spacing.

About SQL Formatting

SQL formatting makes queries more readable and maintainable by applying consistent styling rules. Well-formatted SQL is easier to understand, debug, and modify.

Formatting Benefits

  • Readability: Properly indented and spaced SQL is easier to read
  • Debugging: Issues are easier to spot in well-formatted code
  • Maintenance: Team members can understand and modify queries easily
  • Code Review: Consistent formatting makes reviews more effective
  • Version Control: Formatted queries show clearer diffs

Formatting Styles

Standard Format

Major keywords (SELECT, FROM, WHERE, etc.) on their own lines with consistent indentation for conditions.

SELECT id, name, email
FROM users
WHERE status = 'active'
  AND created_at > '2024-01-01'
ORDER BY name ASC
Compact Format

Single line format for simple queries, useful for inline documentation.

SELECT id, name, email FROM users WHERE status = 'active' ORDER BY name ASC
Expanded Format

Maximum readability with each column and condition on its own line.

SELECT
  id,
  name,
  email
FROM
  users
WHERE
  status = 'active'
  AND created_at > '2024-01-01'
ORDER BY
  name ASC

Best Practices

  • Use uppercase for SQL keywords (SELECT, FROM, WHERE)
  • Use lowercase for table and column names
  • Indent subqueries and conditions consistently
  • Align JOIN conditions with the JOIN keyword
  • Put each column in SELECT on its own line for complex queries
  • Use meaningful aliases for tables and columns
  • Add comments for complex logic

Example Transformations

Before Formatting
select u.id,u.name,u.email,o.order_date,o.total from users u join orders o on u.id=o.user_id where u.status='active' and o.total>100 order by o.order_date desc;
After Formatting
SELECT u.id, u.name, u.email, o.order_date, o.total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.status = 'active'
  AND o.total > 100
ORDER BY o.order_date DESC;
Browse Tools

Tool Navigation

629+ tools across 43 categories