</>DevTools

SQLSQL Formatter

Format and beautify SQL queries

SQL Formatter Complete Guide

SQL Formatter is a free online tool that automatically reformats messy, single-line SQL queries into a clean, readable layout. It supports major dialects including Standard SQL, MySQL, and PostgreSQL, handling keyword casing and indentation automatically. An essential tool for code reviews, query debugging, and enforcing team style consistency.

Supported Dialects

SQL syntax varies between databases. Selecting the correct dialect gives you formatting optimized for your specific DB.

Standard SQL

Follows ANSI/ISO SQL standards. Use for database-agnostic queries. Preserves double-quote (") identifiers and standard JOIN syntax.

MySQL

Correctly formats backtick (`) identifier quoting, LIMIT x OFFSET y, and MySQL-specific functions like GROUP_CONCAT. Ideal for Laravel, Django MySQL backend projects.

PostgreSQL

Recognizes double-quote identifiers, RETURNING clauses, :: type casts, and array/JSON operators (->>, @>). Optimal for Supabase and AWS Aurora PostgreSQL environments.

SQL Formatting Style Rules

Keyword Casing

SQL keywords (SELECT, FROM, WHERE, JOIN, etc.) are uppercased by convention. The formatter normalizes them automatically.

Indentation and Line Breaks

Each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts on a new line. Subqueries and JOIN conditions are indented by 2 spaces. Long SELECT column lists are placed one per line for readability.

Before vs After Example

Here is a real-world formatting comparison:

-- Before
select u.id,u.name,count(o.id) as order_count from users u left join orders o on u.id=o.user_id where u.created_at>='2024-01-01' group by u.id,u.name having count(o.id)>5 order by order_count desc limit 20

-- After (PostgreSQL)
SELECT
  u.id,
  u.name,
  COUNT(o.id) AS order_count
FROM
  users u
  LEFT JOIN orders o ON u.id = o.user_id
WHERE
  u.created_at >= '2024-01-01'
GROUP BY
  u.id,
  u.name
HAVING
  COUNT(o.id) > 5
ORDER BY
  order_count DESC
LIMIT
  20

Frequently Asked Questions

  • Does formatting change query results? — No. Only whitespace and line breaks change; execution results remain identical.
  • Are subqueries and CTEs formatted? — Yes. WITH clauses, nested subqueries, and UNIONs are all auto-indented.
  • Is my data sent to a server? — No. All processing happens in the browser, making it safe for sensitive queries.
  • Is T-SQL (SQL Server) supported? — Currently Standard SQL, MySQL, and PostgreSQL are supported. T-SQL formatted under Standard SQL mode works in most cases.

Tip: Copy a SQL query from the browser DevTools Network tab and paste it here for instant readability.

🔗Related Tools💻 Regex / Code