SQL Formatter
Free web tool: SQL Formatter
Options
About SQL Formatter
The SQL Formatter is a free online tool that beautifies, minifies, and syntax-highlights SQL queries. Choose your SQL dialect — MySQL, PostgreSQL, Oracle, SQL Server, or SQLite — and the formatter applies dialect-aware keyword recognition along with consistent styling: keywords are color-coded in blue, strings in green, numbers in orange, and comments in gray. Major clauses (SELECT, FROM, WHERE, JOIN, ORDER BY, GROUP BY) start on new lines, and subordinate clauses (AND, OR, ON, JOIN conditions) are indented for visual hierarchy.
The tool provides a toggle to control keyword casing: uppercase (SELECT, FROM, WHERE) for traditional SQL style or lowercase (select, from, where) for modern code conventions. The minify function compresses any query into a single line by collapsing all whitespace. Line numbers in the output panel make it easy to reference specific parts of large queries during code reviews or debugging sessions.
Each dialect adds its own keyword set to the highlighter: MySQL recognizes AUTO_INCREMENT, ENGINE, and SHOW; PostgreSQL handles RETURNING, ILIKE, and SERIAL; Oracle supports ROWNUM, NVL, and CONNECT BY; SQL Server highlights TOP, NOLOCK, and MERGE; SQLite detects AUTOINCREMENT, PRAGMA, and GLOB. All processing runs entirely in your browser — no SQL query is ever sent to a server, making it safe for production queries containing sensitive table names or business logic.
Key Features
- SQL dialect selection: MySQL, PostgreSQL, Oracle, SQL Server, SQLite — each with dialect-specific keyword recognition
- Syntax highlighting: keywords in blue, strings in green, numbers in orange, comments in gray — all via regex-based tokenizer
- Keyword casing toggle: uppercase (SELECT) or lowercase (select) to match your team's coding style
- One-click minify to compress SQL into a single line for log searching, URL embedding, or configuration storage
- Line numbers in the output panel for easy reference during code reviews and debugging
- Smart newline insertion: major clauses start on new lines with subordinate clauses indented for clear hierarchy
- Sample SQL loader to quickly test formatting without typing a query from scratch
- One-click copy of formatted or minified result to clipboard
- 100% client-side processing — your SQL never leaves your browser
- Dark mode support with full accessibility for all controls and highlighted output
Frequently Asked Questions
How does dialect selection affect formatting?
Each dialect (MySQL, PostgreSQL, Oracle, SQL Server, SQLite) adds its own set of keywords to the formatter and syntax highlighter. For example, selecting MySQL adds AUTO_INCREMENT, ENGINE, SHOW, and DESCRIBE to the recognized keyword list. Selecting PostgreSQL adds RETURNING, ILIKE, SERIAL, and LATERAL. These dialect-specific keywords are properly uppercased (or lowercased) during formatting and highlighted in blue in the output. The base SQL formatting rules (newlines, indentation) remain the same across all dialects.
How does syntax highlighting work?
The highlighter uses a regex-based tokenizer that processes SQL character by character, identifying four token types: strings (single-quoted text, shown in green), comments (-- single-line and /* */ multi-line, shown in gray), numbers (shown in orange), and text (everything else). Keywords within text tokens are then matched against the full keyword list (base + dialect-specific) and highlighted in blue. Because strings and comments are tokenized first, keywords appearing inside quoted strings or comments are never falsely highlighted.
What is the difference between uppercase and lowercase keyword mode?
The uppercase keywords toggle controls whether SQL keywords like SELECT, FROM, WHERE, JOIN are formatted in UPPERCASE or lowercase. Uppercase is the traditional SQL convention used in most documentation and database tools. Lowercase is increasingly popular in modern codebases where SQL is embedded in application code. The toggle only affects the Format action — Minify preserves the original casing of your input.
How does the formatter handle JOIN clauses?
The formatter recognizes INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, CROSS JOIN, and their OUTER variants as major clauses that start on new lines. The ON condition is indented beneath the JOIN to show it belongs to that join. This makes complex multi-table queries with several joins easy to follow visually.
What is the difference between Format and Minify?
Format (beautify) adds line breaks, indentation, keyword casing, and syntax highlighting to make SQL human-readable. Minify collapses all whitespace into single spaces, producing a compact single-line query. Minified SQL is useful for searching in log files, embedding in URL parameters, or storing in configurations where line breaks are not supported. Both actions produce syntax-highlighted output.
Does the formatter validate SQL syntax?
No, this is a formatting and highlighting tool, not a parser or validator. It applies text transformation rules (keyword detection, newline insertion, indentation, color coding) without parsing the SQL into an abstract syntax tree. This means it will format and highlight syntactically incorrect SQL without raising errors — the formatting and color coding still help you visually identify structural issues.
Can I turn off line numbers?
Yes. There is a "Line numbers" checkbox in the options panel. Unchecking it removes the line number column from the output, giving you a cleaner view of the formatted SQL. This setting is independent of formatting and highlighting — you can toggle it on or off at any time without reformatting.
Is my SQL data safe?
Yes. All formatting, minification, and syntax highlighting happen entirely in your browser using JavaScript. No SQL query is ever transmitted to a server, stored, or logged. This makes the tool safe for production queries, queries referencing sensitive table or column names, and queries containing business logic.