Format SQL Query Online

Beautify messy SQL queries with proper indentation and formatting.

Formatting SQL for Readability

Long SQL queries generated by ORMs, query builders, or database logs are often a single unreadable line. Our SQL formatter adds proper indentation, line breaks, and keyword capitalization so you can understand the query structure at a glance — essential for debugging performance issues and reviewing query logic.

The formatter handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, CTEs (WITH clauses), subqueries, JOINs of all types, UNION/INTERSECT/EXCEPT, and window functions. It produces output that follows standard SQL formatting conventions used in production codebases.

This is particularly useful when debugging slow queries from your database's slow query log, reviewing SQL in pull requests, or reverse-engineering what an ORM like Django, SQLAlchemy, or Prisma is actually generating behind the scenes.

Tips

  • Capitalize SQL keywords (SELECT, FROM, WHERE) — it's the most common convention in professional codebases.
  • Put each column in a SELECT list on its own line — cleaner diffs in version control.
  • Format ORM-generated queries to verify they're doing what you expect — you might catch N+1 patterns or missing indexes.
  • Use CTEs (WITH clauses) instead of deeply nested subqueries for better readability.

Ready to get started?

Format SQL Query

New tools every week

Get notified. No spam.