ποΈ
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.
- 1Tokenizer splits the SQLA 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.
- 2Compound keywords are mergedAfter 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.
- 3Block layout or minificationIn 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.
- 4Syntax highlighting via regexThe 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
CSS Beautifier
Pretty-print minified CSS with consistent indentation, or minify it. Optional alphabetical property sorting for predictable diffs.
Try it
XML Formatter & Validator
Pretty-print and validate XML using your browser's native DOM parser. Includes minified output for production use.
Try it
HTML Beautifier & Minifier
Pretty-print or minify HTML with proper nesting indentation. Preserves content inside <pre>, <script>, <style> blocks.
Try it