Spoold Logo
/

SQL Formatter & Beautifier

Guide
SQL inputStandard SQL
Formatted output

Guide: SQL Formatter & Beautifier

↑ Back to tool

What is this tool?

This SQL formatter is a free online tool that formats and beautifies SQL queries in your browser. It supports 15+ SQL dialects including PostgreSQL, MySQL, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), BigQuery, Redshift, Spark SQL, Hive, Trino, DB2, N1QL, MariaDB, and SingleStoreDB. Paste your query, choose a dialect and indentation style, and get clean, indented SQL instantly. The tool uses Monaco (the VS Code engine) for both input and output with full SQL syntax highlighting. You can copy the result, download it as a .sql file, or share via link. All processing runs client-side—your SQL never leaves your browser.

Why use a SQL formatter?

Complex SQL with joins, subqueries, CTEs, and window functions is nearly impossible to read when it's on a single line or inconsistently indented. A SQL beautifier makes queries readable and reviewable, helping you debug issues faster and standardize style across a team. This tool lets you paste any SQL and get formatted output instantly—no CLI, IDE plugin, or installation needed.

For Developers

  • • Format queries for code reviews and PRs
  • • Standardize SQL style across a team
  • • Debug complex joins, CTEs, and subqueries

For Data Teams

  • • Clean up ad-hoc queries before sharing
  • • Format BigQuery, Redshift, or Spark SQL
  • • Prepare SQL for documentation or wikis

Key features

  • 15+ SQL dialects — Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), BigQuery, Redshift, Spark SQL, Hive, Trino, DB2, N1QL (Couchbase), SingleStoreDB.
  • Keyword casing — Toggle uppercase keywords (SELECT, FROM, WHERE) for readability, or preserve original casing.
  • Configurable indent — Choose 2 or 4 spaces for indentation via a dropdown.
  • Live formatting — Output updates automatically as you type or change settings—no button click needed.
  • Multi-query support — Handles multiple SQL statements separated by semicolons, with blank lines between queries.
  • Monaco editor — Both input and output use Monaco (the VS Code engine) with SQL syntax highlighting, line numbers, and word wrap.
  • Copy — Copy the formatted SQL to the clipboard with one click.
  • Download — Download the result as a .sql file.
  • Share — Generate a link that encodes your SQL (base64 in the URL fragment) so you can share the query with others.
  • 100% client-side — Your SQL never leaves your browser. Powered by the sql-formatter library.

How this tool works (step-by-step)

  1. Paste your SQL — Paste your SQL query into the input editor. Use "Load sample" to try it with example data.
  2. Choose a dialect — Select the SQL dialect from the dropdown (default: Standard SQL). This ensures dialect-specific syntax is handled correctly.
  3. Adjust options — Toggle the UPPER button for keyword casing and select 2 or 4 space indent size.
  4. Review the output — The formatted SQL appears instantly in the right panel with syntax highlighting.
  5. Copy, download, or share — Copy the result, download as .sql, or Share to get a link.

Real-world examples with code snippets

Simple SELECT with JOIN

Input

SELECT u.id, u.name, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE o.status = 'completed' AND o.total > 100 ORDER BY o.total DESC LIMIT 10;

Output (formatted, uppercase keywords)

SELECT
  u.id,
  u.name,
  o.total
FROM
  users u
  JOIN orders o ON u.id = o.user_id
WHERE
  o.status = 'completed'
  AND o.total > 100
ORDER BY
  o.total DESC
LIMIT
  10;

CTE (Common Table Expression)

Input

WITH active_users AS (SELECT id, name FROM users WHERE active = true), user_orders AS (SELECT user_id, SUM(total) as total_spent FROM orders GROUP BY user_id) SELECT a.name, u.total_spent FROM active_users a JOIN user_orders u ON a.id = u.user_id ORDER BY u.total_spent DESC;

Output (formatted)

WITH
  active_users AS (
    SELECT
      id,
      name
    FROM
      users
    WHERE
      active = true
  ),
  user_orders AS (
    SELECT
      user_id,
      SUM(total) AS total_spent
    FROM
      orders
    GROUP BY
      user_id
  )
SELECT
  a.name,
  u.total_spent
FROM
  active_users a
  JOIN user_orders u ON a.id = u.user_id
ORDER BY
  u.total_spent DESC;

Use cases

ScenarioHow this tool helps
Code reviewsFormat SQL before pasting in a PR or ticket so reviewers can read it at a glance.
Debugging queriesPaste a long one-liner from logs or error output; formatting reveals the structure and helps spot issues.
Data team collaborationStandardize query style across analysts using different editors, IDEs, or notebooks.
DocumentationFormat SQL for READMEs, wikis, or runbooks. Download as .sql or copy formatted output.
Share a queryShare a link so a teammate can open the same SQL formatted—no file attachments needed.

Best practices for SQL formatting

  • Select the correct dialect — Different databases have different keywords and syntax (e.g. LIMIT in MySQL vs TOP in T-SQL). Choosing the right dialect ensures correct formatting.
  • Uppercase keywords — Using SELECT, FROM, WHERE in uppercase is a widely adopted convention that visually separates keywords from identifiers.
  • Be consistent with indentation — Pick 2 or 4 spaces and use it across your project. Consistency matters more than the specific number.
  • Format before committing — Run SQL through the formatter before adding it to version control or documentation, just like you would lint code.
  • Use CTEs for readability — Break complex subqueries into named CTEs (WITH clauses). The formatter will indent them clearly.

Common mistakes & how to avoid them

  • Wrong dialect selected — If the formatted output looks odd (e.g. keywords not recognized), switch to the correct dialect. PostgreSQL, MySQL, and T-SQL have different reserved words.
  • Incomplete SQL — The formatter works best with complete statements. A partial query (missing closing parenthesis or semicolon) may not format correctly.
  • Expecting validation — This is a formatter, not a validator. It reformats the text but doesn't check if your SQL is semantically correct or will execute successfully.
  • Stored procedures may need PL/SQL or T-SQL — If you're formatting procedural SQL (BEGIN/END, DECLARE), select the PL/SQL or T-SQL dialect for best results.

FAQ

Which SQL dialects are supported?

Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, T-SQL (SQL Server), PL/SQL (Oracle), BigQuery, Redshift, Spark SQL, Hive, Trino, DB2, N1QL (Couchbase), and SingleStoreDB—15 dialects total.

Does it validate SQL?

No. The formatter parses and reformats your SQL for readability. If it can't parse the input, the original text is returned unchanged. It doesn't check if the SQL will execute successfully.

Is my SQL sent to a server?

No. All formatting runs in your browser using the sql-formatter library. Your SQL never leaves your machine.

Can I format stored procedures?

Yes. Choose the PL/SQL dialect for Oracle procedures or T-SQL for SQL Server procedures. The formatter handles most procedural SQL including BEGIN/END blocks and DECLARE statements.

Can I format multiple queries at once?

Yes. Separate queries with semicolons. The formatter will add blank lines between each query for readability.

What formatter library is used?

The tool uses the sql-formatter npm package, which is the most popular open-source SQL formatting library. It supports dialect-specific parsing and configurable output.

Does it handle comments?

Yes. Both single-line (--) and multi-line (/* */) comments are preserved in the formatted output.

Is it free?

Yes. The SQL formatter is completely free with no sign-up required. All processing runs in your browser.

This tool is commonly searched as SQL formatter, SQL beautifier, format SQL online, SQL pretty printer, SQL indenter, beautify SQL, SQL lint, format PostgreSQL query, format MySQL query, and SQL code formatter. It handles any SQL dialect—from simple SELECTs to complex CTEs and stored procedures—all without leaving the browser.

Similar tools

You might also find these developer tools useful:

Conclusion

A SQL formatter makes complex queries readable and reviewable in seconds. This tool supports 15+ dialects, configurable keyword casing and indentation, live formatting, copy, download, and share—all running entirely in your browser with no sign-up. Use it for code reviews, debugging, documentation, or standardizing SQL style across your team.