SQL Formatter

Format SQL queries with proper indentation, line breaks, and uppercase keywords. Free online beautifier for SELECT, JOIN, WHERE, and CTEs. Free online.

How to use

  1. Paste SQL — Enter your SQL query
  2. Format — See the formatted output instantly
  3. Copy — Copy the formatted SQL

What Is a SQL Formatter?

A SQL formatter takes a single-line or sloppily indented SQL query and rewrites it with consistent indentation, line breaks before major clauses, and standardized keyword capitalization. Readable SQL is dramatically easier to debug, review in pull requests, and maintain over time — especially as queries grow to span dozens of joins and CTEs.

What the Formatter Does

  • Uppercases reserved keywords: SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, HAVING, UNION, etc.
  • Inserts line breaks before each major clause so the structure is visible at a glance
  • Indents columns and conditions consistently using spaces (configurable to match your team's style)
  • Aligns subqueries and CTEs so nested logic stays visually distinct
  • Normalizes whitespace by collapsing runs of spaces and trimming trailing whitespace

Why Formatting Matters

Minified single-line queries hide bugs. A missing comma in a SELECT list, an accidental cross join from a forgotten ON clause, or a WHERE condition attached to the wrong subquery are all obvious in formatted SQL but invisible in a 600-character one-liner. Code reviewers can spot logic issues in seconds when the structure is laid out clearly. New team members onboard faster when every query in the codebase follows the same shape.

Supported SQL Dialects

The formatter targets standard ANSI SQL constructs that work across PostgreSQL, MySQL, SQL Server, SQLite, and Snowflake: SELECT/INSERT/UPDATE/DELETE statements, JOINs (INNER, LEFT, RIGHT, FULL, CROSS), subqueries, CTEs (WITH clauses), window functions (OVER), CASE expressions, and UNIONs. Dialect-specific syntax (e.g. T-SQL hints, MySQL backticks) is preserved as-is rather than being rewritten.

Workflow Tips

Run formatting before committing SQL files to keep your repository diff-friendly — every reviewer benefits when whitespace changes don't pollute the diff. Format generated queries from ORMs to understand what your code is actually executing. Reformat queries pasted from logs to debug slow performance.

Privacy

Your queries are formatted entirely in your browser. They are never sent to a server, never logged, and never analyzed — safe even for production schemas with sensitive table or column names.

Format JSON with the JSON Formatter. Minify CSS with the CSS Minifier. Format and validate JSON with JSON Validator.

Frequently asked questions

What SQL dialects are supported?

Standard SQL keywords are supported. The formatter works with MySQL, PostgreSQL, SQLite, and SQL Server queries.

Does it validate SQL?

No. It formats the text structure but doesn't validate query correctness.

Does it handle subqueries?

Basic subqueries are formatted. Complex nested queries may need manual adjustment.

Related free tools

  • XML Formatter & Minifier — Beautify or minify any XML — SOAP, RSS, SVG, sitemap. Browser-based parser.
  • XML to JSON Converter — Parse any well-formed XML into a clean JSON tree with attributes and arrays.
  • JSON to XML Converter — Convert JSON to well-formed XML — supports attributes, custom root, declaration.
  • CSV Viewer — Open CSV or TSV files in your browser — sort, search, paginate, export filtered view.
  • JSON to CSV Converter — Convert JSON data to CSV format. Export to spreadsheets easily.
  • CSV to JSON Converter — Convert CSV data to JSON format. Useful for API development.
  • JSON Formatter — Format, beautify, or minify JSON with customizable indentation.
  • JSON Validator — Validate JSON syntax and find errors with line and column numbers.
  • HTML Minifier — Compress HTML by removing comments, whitespace, and line breaks.
  • CSS Minifier — Minify CSS by stripping comments, whitespace, and unnecessary characters.
  • JavaScript Minifier — Compress JavaScript by removing comments, whitespace, and empty lines.
  • Base64 Encoder/Decoder — Encode text to Base64 or decode Base64 back to text. UTF-8 support.

Browse all free tools · Guides and tutorials · PDF tools · Developer tools · Text tools · SEO tools