🧠 Built by SuperML.dev · SuperML.org

Having issues with buttons or file uploads? If tools aren't responding, please or press Ctrl+F5 (or Cmd+R on Mac).

← Back to Blog

Free SQL Formatter — Format and Beautify SQL Queries in Your Browser

Format messy SQL queries into readable, well-indented code. Supports MySQL, PostgreSQL, SQLite, and more. Runs in your browser — no queries sent to any server.

Production SQL queries can become difficult to read — especially when copied from logs, ORMs, or legacy codebases. SimpleTools SQL Formatter transforms dense, single-line SQL into clean, readable code with consistent indentation and keyword capitalisation.

What Does SQL Formatting Do?

Before formatting:

select u.id,u.name,u.email,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' and u.status='active' group by u.id,u.name,u.email having count(o.id)>0 order by order_count desc limit 50;

After formatting:

SELECT
  u.id,
  u.name,
  u.email,
  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'
  AND u.status = 'active'
GROUP BY
  u.id,
  u.name,
  u.email
HAVING
  COUNT(o.id) > 0
ORDER BY
  order_count DESC
LIMIT
  50;

Readable at a glance — easier to review, debug, and discuss.

Features

  • Multi-dialect support: MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle, BigQuery, SparkSQL
  • Keyword casing: Uppercase keywords, lowercase identifiers, or preserve existing case
  • Indentation control: 2 spaces, 4 spaces, or tabs
  • Inline vs. expanded: Choose compact formatting or full expansion
  • Multiple statements: Format SQL files with multiple queries separated by semicolons
  • Comment preservation: Line comments (--) and block comments (/* */) are preserved
  • Copy formatted SQL: One-click copy to clipboard
  • Minify mode: Also minify SQL to a single line (useful for embedding in code strings)

Why Format SQL in Your Browser?

SQL queries — especially from production systems — often contain:

  • Database schema details: Table and column names reveal your data architecture
  • Business logic: Filter conditions, join structures, and calculations expose business rules
  • Sensitive data fragments: Inline values from queries can include customer IDs, emails, or other PII

Sending these to a cloud SQL formatter is an unnecessary risk.

SimpleTools SQL Formatter:

Your SQL queries never leave your browser
Works offline — format queries without internet
No account or API key needed
Free for any number of queries

How It Works

The tool uses sql-formatter — a widely-used open-source JavaScript library for SQL formatting. It runs entirely in the browser as a JavaScript module:

  1. Your SQL text is parsed by the library’s tokenizer into a token stream (keywords, identifiers, operators, literals)
  2. The formatter reassembles the tokens with proper whitespace, line breaks, and indentation based on SQL grammar rules
  3. The formatted output is displayed and ready to copy

The library handles complex cases like subqueries, CTEs (WITH clauses), window functions (OVER (PARTITION BY ...)), and nested function calls.

How to Use the SQL Formatter

  1. Visit simpletools.one/sql-formatter
  2. Paste your SQL query in the input panel
  3. Select the SQL dialect (MySQL, PostgreSQL, etc.) if needed for dialect-specific syntax
  4. Choose your formatting preferences (keyword case, indentation)
  5. The formatted SQL appears instantly in the output panel
  6. Click Copy to copy to clipboard

Common Use Cases

Reviewing query performance: Formatted SQL is easier to analyse for missing indexes, unnecessary joins, or inefficient subqueries.

Code review: During PR review, unformatted SQL in migration files or query constants is hard to read. Format first, then review.

Debugging ORM-generated queries: ORMs like SQLAlchemy, Hibernate, and ActiveRecord generate queries that are hard to read. Log the query, format it, then understand the issue.

Documentation: Include formatted SQL in documentation, READMEs, or runbooks.

Collaboration: Share formatted SQL with teammates who aren’t familiar with the query structure.

SQL Formatting Best Practices

  1. Uppercase SQL keywords: Makes keywords visually distinct from identifiers
  2. One clause per line: SELECT, FROM, WHERE, GROUP BY, ORDER BY each on their own line
  3. Align column lists: Indent select columns with a consistent offset
  4. Alias tables: Short, consistent aliases (u for users, o for orders) improve readability
  5. Comment complex logic: Add comments before complex filter conditions or joins

Format your SQL queries at simpletools.one/sql-formatter — readable code, complete privacy, free forever.

Enjoyed this post?

Subscribe to our newsletter or explore more privacy-friendly tools!

Explore Tools