Best SQL Formatter Online — Free, All Dialects

Format SQL queries online for MySQL, PostgreSQL, T-SQL, and SQLite. Consistent indentation, keyword casing, and CTE formatting — browser-based, no data sent to server.

Why Use a Dedicated SQL Formatter

SQL written under time pressure — in SSMS, a terminal, or an ORM — accumulates inconsistent indentation, mixed keyword casing, and cramped clause formatting. A good SQL formatter applies consistent style across dialects: uppercase keywords, aligned clauses, and proper line breaks for JOINs, WHERE conditions, and CTEs.

  • Multi-dialect support: MySQL, PostgreSQL, T-SQL (SQL Server), SQLite, and generic SQL
  • Uppercase keywords: Standard convention applied consistently — SELECT, FROM, WHERE, JOIN
  • CTE formatting: WITH cte AS (...) blocks indented and structured for readability
  • Subquery indentation: Nested queries indented relative to their parent clause
  • Browser-based: Queries never leave your device — safe for internal schema and business logic
  • No account needed: Paste and format instantly

Choose the Right Dialect

Before and After Example

  • Input (minified): select u.id,u.name,count(o.id) as orders from users u left join orders o on u.id=o.user_id where u.active=1 group by u.id,u.name having count(o.id)>0 order by orders desc
  • Output (formatted): Each clause on its own line, JOIN conditions indented, keywords uppercased, column list wrapped and aligned
  • Use before code review: Formatted SQL is significantly easier to review for logic errors and missing conditions
  • Use for documentation: Formatted queries in README files and wikis are more readable for new team members

Privacy and Data Handling

All SQL formatting runs locally in your browser. Query content — including table names, column names, and inline values — is never transmitted to any server. Safe for internal database queries and proprietary business logic.

Frequently Asked Questions

Does SQL formatting change how a query executes?

No. SQL formatting only adds whitespace and line breaks, which SQL parsers ignore completely. A formatted query and its minified original produce identical execution plans. Formatting is purely for human readability — it makes queries easier to understand, review, and debug. The database doesn't care about indentation or keyword casing (SQL is case-insensitive for keywords in most databases, though identifiers may be case-sensitive depending on collation settings).

What SQL formatter does VS Code use?

VS Code doesn't include a built-in SQL formatter. Common extensions: SQL Formatter (uses the same sql-formatter library), SQLTools (includes formatting as part of its database connection features), and Prettier with the prettier-plugin-sql plugin. For team consistency, configure a formatter in settings.json with "editor.formatOnSave": true and an agreed dialect setting. For one-off query formatting without IDE setup, paste into this online tool.

Should I store formatted or minified SQL in source code?

Always store formatted (readable) SQL in source code. Minified SQL saves negligible bytes and makes maintenance significantly harder. For SQL stored in application code as string literals (Python, JavaScript, Java), use multi-line strings and format the SQL within them. For SQL in migration files or stored procedures, formatted SQL is non-negotiable for code review. The only case for compact SQL is in generated query strings at runtime where a query builder or ORM creates the SQL programmatically — but even then, logging the formatted version during debugging is valuable.