SQL Formatter

SQL Formatter

Format and beautify SQL queries with proper indentation, keyword capitalization, and readability improvements. Perfect for code reviews, documentation, and team collaboration with customizable styling options.

sql
format
beautify
Share this tool:
Quick Presets
Common SQL samples for quick formatting
Input
Paste SQL to normalize formatting, keyword casing, and indentation.
How it works: Formats SQL using a regex-based parser that normalizes keyword casing, adds line breaks at major clauses, and applies consistent indentation.

What is SQL Formatter?

The SQL Formatter beautifies SQL queries by adding consistent indentation, line breaks, and keyword casing. It supports multiple SQL dialects including MySQL, PostgreSQL, SQL Server, and SQLite. The tool handles complex queries with subqueries, joins, CTEs, and window functions. All processing happens in the browser.

How does SQL Formatter work?

This tool parses SQL text and reformats it with configurable options: indent size, keyword case (upper, lower, preserve), and comma placement (before or after). It recognizes SQL keywords, identifiers, strings, and comments to produce properly structured output.

Key Features

  • Formats SQL with configurable indentation
  • Uppercase, lowercase, or preserve keyword case
  • Supports MySQL, PostgreSQL, SQL Server, SQLite
  • Handles subqueries, joins, CTEs, window functions
  • Comma placement options
  • Copy formatted SQL to clipboard
  • Download as .sql file
  • Runs in the browser with no uploads

Common Use Cases

When and why you might need this tool
  • Beautifying minified SQL for debugging

    Format a compact SQL query from a log or ORM output into readable code.

  • Standardizing SQL in code reviews

    Format SQL statements before committing so the team uses consistent style.

  • Learning SQL structure

    Format complex queries to understand how joins, subqueries, and CTEs nest.

  • Preparing SQL for documentation

    Format example queries for inclusion in API documentation or tutorials.

How to Use This Tool

Step-by-step guide to get the best results
1

Paste SQL

Enter a SQL query in the input area.

2

Choose options

Set dialect, indent size, keyword case, and comma placement.

3

Format

Click Format. The tool reformats the query.

4

Copy the result

Copy the formatted SQL or download it as a file.

Pro Tips

  • 1

    Uppercase keywords is the most common SQL style convention.

  • 2

    Use 2-space indentation for compact output.

  • 3

    The tool handles CTEs (WITH clauses), subqueries, and complex JOIN chains.

  • 4

    Try different comma placement options to match your team's style.

Frequently Asked Questions

Which SQL dialects are supported?

The tool supports MySQL, PostgreSQL, SQL Server, and SQLite. It recognizes dialect-specific keywords and syntax.

Can I change keyword casing?

Yes. You can set keywords to uppercase, lowercase, or preserve the original case.

Is my SQL uploaded to a server?

No. All formatting happens in your browser using JavaScript. The SQL never leaves your device.

Does it handle complex queries?

Yes. The formatter handles subqueries, joins, CTEs, window functions, and nested expressions.

Will formatting change query behavior?

No. Formatting only changes whitespace and keyword casing. The query logic and results are identical.