SQL Formatter

Beautify and format SQL queries with proper indentation and keyword casing. 100% client-side.

Input
Output
Paste a SQL query above to format it.

How to Use the SQL Formatter

  1. Paste your SQL query into the input area on the left (or top on mobile).
  2. Choose a format mode — Standard (default) for full formatting, Compact for minimal whitespace, Uppercase Keywords, or Lowercase Keywords.
  3. View the result — the formatted SQL appears on the right with proper indentation and line breaks.
  4. Copy or download — use the buttons above the output to copy to clipboard or download as a .sql file.

What This Tool Does

This SQL formatter takes raw, unformatted SQL queries and restructures them for readability. It adds line breaks before major clauses (SELECT, FROM, WHERE, JOIN, etc.), indents column lists and conditions, and applies consistent keyword casing. The formatter preserves string literals and does not modify the content inside quoted values. Everything runs in your browser with no server communication.

Features

  • Standard formatting — newlines before major clauses with indented continuation lines
  • Compact mode — minimal whitespace for embedding SQL in code or logs
  • Keyword casing — uppercase or lowercase all SQL keywords while preserving identifier case
  • String literal preservation — content inside single and double quotes is never modified
  • Subquery handling — parenthesized subqueries are indented for clarity
  • Privacy — your SQL never leaves your browser

Supported SQL Keywords

The formatter recognizes the full set of standard SQL keywords including: SELECT, FROM, WHERE, JOIN (LEFT, RIGHT, INNER, OUTER, CROSS, FULL), ON, AND, OR, ORDER BY, GROUP BY, HAVING, LIMIT, OFFSET, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE, CREATE TABLE, ALTER TABLE, DROP, INDEX, WITH, CASE/WHEN/THEN/ELSE/END, and aggregate functions (COUNT, SUM, AVG, MIN, MAX).

Why Format SQL?

Well-formatted SQL is dramatically easier to read, debug, and maintain. When a complex query is written on a single line, finding a specific condition or join clause requires careful scanning. Formatted SQL makes the query's logical structure immediately visible: you can see which tables are joined, what conditions are applied, and how results are grouped and ordered — all at a glance.

SQL Style Conventions

There is no universal standard for SQL formatting, but common conventions include: uppercase keywords (SELECT, FROM, WHERE) to distinguish them from table and column names, one clause per line for major keywords, indented column lists under SELECT, and aligned conditions under WHERE. This tool follows these widely adopted conventions by default.

Compact vs. Standard Mode

Standard mode prioritizes readability with generous line breaks and indentation. Compact mode reduces whitespace to a minimum, keeping the query on fewer lines while still maintaining basic keyword separation. Use compact mode when SQL is embedded in application code, logged in monitoring systems, or when screen real estate is limited.

SQL Formatting Conventions

While there is no universal SQL style guide, most teams follow common conventions: uppercase keywords (SELECT, FROM, WHERE), lowercase table and column names, each major clause on its own line, and consistent indentation for column lists and conditions. This formatter applies these conventions automatically, saving time during code reviews and improving readability across your team. For other formatting tools, check out our JSON Formatter, CSV/JSON Converter, and Diff Checker for comparing SQL before and after changes.

Frequently Asked Questions

A SQL formatter takes raw or messy SQL code and restructures it with consistent indentation, line breaks, and keyword casing. This makes the query easier to read, debug, and maintain. The formatter adds newlines before major clauses like SELECT, FROM, WHERE, and JOIN, and indents column lists and conditions.
No. This SQL formatter runs entirely in your browser using JavaScript. Your SQL queries never leave your device. There is no server-side processing, no logging, and no data collection. This is especially important for SQL containing sensitive table or column names.
This tool formats SQL but does not validate or execute it. It recognizes SQL keywords and structures them with proper formatting, but it does not check whether your query is syntactically valid or would run successfully against a database. For syntax validation, use your database's query analyzer.
This formatter works with standard ANSI SQL and is compatible with common dialects including MySQL, PostgreSQL, SQL Server, SQLite, and Oracle. It recognizes standard keywords like SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, UNION, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, and WITH (CTEs).
Standard mode adds newlines before major clauses and indents continuation lines for maximum readability. Compact mode minimizes whitespace while keeping the query on fewer lines, which is useful for embedding SQL in code or log files. Both modes handle keyword casing according to your selected preference.