SQL Formatter

Format, beautify, and syntax-highlight your SQL queries online. Paste your SQL, pick your options, and copy the clean result.

Input SQL

Formatted SQL

SELECT
    u.id,
    u.name,
    u.email,
    o.total_amount,
    o.created_at
FROM  users  u  inner
JOIN  orders  o  ON  u.id  =   o.user_id
WHERE  o.status  =   'completed'  AND  o.total_amount  >   100  order  by  o.created_at  DESC
LIMIT  50;

What Is SQL Formatting?

SQL formatting is the process of restructuring a SQL query to improve readability. A well-formatted query uses consistent indentation, keyword casing, and line breaks to make the logic clear at a glance. This is especially important when working with complex queries involving multiple joins, subqueries, or conditional expressions.

How to Use This SQL Formatter

  1. Paste your SQL into the input area on the left. It can be a single query or multiple statements separated by semicolons.
  2. Choose keyword casing — UPPERCASE makes keywords stand out from identifiers; lowercase blends them in for a softer style.
  3. Set indentation to 2 or 4 spaces depending on your team's style guide.
  4. Copy the result with one click and paste it into your editor, documentation, or code review.

Features

  • Syntax highlighting — keywords in blue, strings in green, numbers in orange, and comments in gray.
  • Smart formatting — newlines before major clauses (SELECT, FROM, WHERE, JOIN), indented column lists, aligned ON conditions.
  • Minify — compress your SQL to a single line for embedding in code or logs.
  • No dependencies — runs entirely in your browser. Your SQL never leaves your machine.

Supported SQL Dialects

This formatter handles standard SQL syntax used across most database systems including PostgreSQL, MySQL, SQLite, SQL Server, and Oracle. It supports common clauses like SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, as well as window functions (OVER, PARTITION BY), CTEs (WITH), and CASE expressions. The formatting is dialect-agnostic — it focuses on structure rather than vendor-specific extensions.

Tips for Clean SQL

  • Use table aliases (e.g., users u) to keep column references short.
  • Put each selected column on its own line for easier diffs in version control.
  • Use CTEs (WITH) instead of deeply nested subqueries for better readability.
  • Add comments to explain complex business logic within your queries.