Skip to main content

Free SQL Formatter & Beautifier

Pretty-print SQL queries with proper indentation, configurable keyword case, and line breaks on major clauses. Works with any SQL dialect.

Works offline once loaded
Formatted SQL
Formatted SQL appears here…

Common uses

  • Format SQL for Pull Request ReviewsClean up SQL queries before committing to make them readable in code reviews.
  • Format SQL to Find BugsFormatting reveals structural issues like missing JOINs or misaligned conditions.
  • Format SQL for DocumentationMake SQL examples in your docs, blog posts, or tutorials beautiful and easy to read.
  • Format ORM-Generated SQLORMs (Sequelize, Prisma, ActiveRecord) produce single-line SQL β€” format it to debug what they actually generated.
  • Format Reporting QueriesBig analytical SQL queries become unmanageable without formatting. Indent them for clarity.

How It Works

This SQL formatter is built entirely from a hand-written tokenizer and formatter β€” no external library is used. Formatting and syntax highlighting run instantly in the browser as you type, with no server involved.

  1. 1
    Tokenizer splits the SQL
    A character-by-character tokenizer walks your input and breaks it into typed tokens: string literals (handling both backslash escapes and SQL's doubled-quote style), line comments (--), block comments (/* */), operators, parentheses, identifiers, and numbers. Whitespace is collapsed to a single space token.
  2. 2
    Compound keywords are merged
    After tokenizing, a second pass merges adjacent tokens that form multi-word keywords β€” so 'LEFT' followed by 'JOIN' becomes a single 'LEFT JOIN' token, and 'GROUP' followed by 'BY' becomes 'GROUP BY'. This is what lets the formatter treat them as single layout units.
  3. 3
    Block layout or minification
    In format mode, block-starting keywords (SELECT, FROM, WHERE, JOIN, etc.) are placed on their own line at zero indent, and everything that follows is indented. AND/OR force a new indented line. Commas at the top paren level also flush to a new line. In minify mode, all newlines and redundant whitespace are collapsed to a single-space-separated sequence.
  4. 4
    Syntax highlighting via regex
    The formatted output is passed through a single regex that matches comments, string literals, numbers, and identifiers in one sweep. Each match is wrapped in a React span with a color class β€” comments in muted italic, strings in amber, numbers in purple, and SQL keywords (checked against the full keyword set) in teal β€” producing the colored output panel.

Related Tools

Frequently Asked Questions