SQL Formatter & Beautifier

Format and beautify SQL queries with customizable indentation and keyword casing. Free, client-side, no signup.

Your data never leaves your browser Available via MCP

How to Use

  1. Paste your SQL query into the input panel.
  2. Select indentation (2 or 4 spaces) and keyword casing preference.
  3. Click Format to beautify, or Minify to compress to a single line.
  4. Click Copy to copy the formatted result.

Why Format SQL?

Well-formatted SQL is dramatically easier to read, debug, and review in pull requests. A single-line query with 10 JOINs is nearly impossible to parse visually, while the same query with proper line breaks and indentation reveals its structure instantly. Consistent formatting across a codebase reduces cognitive load and makes patterns (like missing WHERE clauses) stand out.

SQL Formatting Conventions

There is no universal SQL formatting standard, but common conventions include: putting each major clause (SELECT, FROM, WHERE, JOIN) on its own line; indenting column lists and conditions; uppercasing SQL keywords while keeping identifiers in their original case; and aligning JOIN conditions. This tool follows these widely-adopted conventions.

Common SQL Patterns

  • SELECT with JOINs — The most common complex query pattern; proper formatting makes the relationship chain clear
  • Subqueries — Nested SELECT statements benefit enormously from indentation to show nesting depth
  • CTEs (WITH clauses) — Common Table Expressions should each be on their own block with clear indentation
  • CASE expressions — Format WHEN/THEN/ELSE on separate lines for readability
  • INSERT with multiple rows — Each VALUES tuple on its own line makes row-by-row review possible

SQL in Modern Development

Despite the rise of ORMs (Object-Relational Mappers) like Prisma, SQLAlchemy, and Sequelize, raw SQL remains essential for complex queries, performance optimization, database migrations, and analytics. Tools like pgFormatter, sql-formatter, and IDE plugins (DataGrip, VS Code SQL extensions) can automatically format SQL in your development workflow.

Related Tools

Convert query results with the JSON to CSV Converter. Format configs with the JSON Formatter or XML Formatter. Test patterns with the Regex Tester. Compare query versions with the Diff Checker. Convert timestamps in results with the Epoch Converter. Decode connection string tokens with the Base64 Encoder.

Frequently Asked Questions

What SQL dialects are supported?
This tool formats standard SQL syntax that works across all major databases including MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. It handles SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, and JOIN queries.
Does this tool validate SQL?
No. This tool formats SQL for readability but does not validate syntax or execute queries. For syntax validation, use your database's query analyzer or a dedicated SQL linter.
What does "Uppercase keywords" do?
When enabled, SQL keywords like SELECT, FROM, WHERE, and JOIN are converted to uppercase while leaving table names, column names, and values unchanged. This is a common convention that improves readability.
Is my data safe?
Yes. All formatting happens entirely in your browser using JavaScript. No SQL queries are sent to any server or database.

Code Examples

Learn how to use this tool programmatically in your favorite language.

Use this tool from AI agents. The CodeTidy MCP Server lets Claude, Cursor, and other AI agents use this tool and 46 others directly. One command: npx @codetidy/mcp

Drop file to load