Free Converter

SQL Query Formatter & Highlighter

Format, beautify, and syntax-highlight SQL queries instantly in your browser. Free, secure, and no upload required.

Drag & Drop a .sql file here

Or paste your SQL query below

Or

About SQL Formatting

SQL queries get long and complex quickly — joins across many tables, nested subqueries, large WHERE clauses with many conditions, complex CASE expressions. Compact SQL crammed onto few lines is unreadable; properly indented SQL with consistent capitalization makes the query structure visible at a glance. Formatting is the difference between a query you can debug and one you can't.

This formatter parses SQL and emits indented, properly-cased output. SQL keywords (SELECT, FROM, WHERE, JOIN, GROUP BY) are typically uppercased, table and column names match source, and indentation reflects nesting (subqueries indented inside their parents, CASE branches indented). Multiple dialect support handles MySQL, PostgreSQL, SQL Server, Oracle, and SQLite differences.

Formatting is non-destructive — the formatted query is functionally identical to the input. Only whitespace and case change.

Why Format SQL

Reading dense unformatted SQL is mentally taxing. Identifying which conditions belong to which JOINs, where subqueries start and end, and how CASE branches relate all become harder when everything is on few lines. Formatted SQL is faster to read and reduces bugs from misreading structure.

Code review benefits especially. Reviewers can quickly grasp what a query does when it's formatted; reading unformatted SQL during review encourages skipping or rubber-stamping. Formatted SQL also produces meaningful diffs when queries change.

How to Format SQL

Paste query, click format.

  1. Paste your SQL: Drop the query into the input area. Single statement or multi-statement input both work.
  2. Choose dialect: Default is generic SQL. Choose MySQL, PostgreSQL, SQL Server, or Oracle for dialect-specific keyword recognition.
  3. Configure options: Indent size (typically 2 or 4 spaces), keyword case (uppercase is most common, lowercase is some teams' preference), comma placement (trailing or leading).
  4. Format: The formatted output appears immediately. Copy or download for use.

Common Use Cases

Technical Details

SQL parsing requires understanding the dialect because different databases extend the grammar in different ways. The formatter typically uses a tokenizer to identify keywords, identifiers, literals, and punctuation, then produces output with rules for whitespace and indentation between tokens.

Indentation rules: SELECT, FROM, WHERE, GROUP BY, ORDER BY each on their own line. Joined tables on subsequent lines indented under FROM. Conditions in WHERE on separate lines for readability. Subqueries in their own indented blocks.

Case conventions: keywords uppercase (SELECT, FROM, WHERE) is most common. Some teams prefer lowercase. Identifiers (table and column names) preserve source case.

Best Practices

Frequently Asked Questions

What dialects are supported?
Common dialects (MySQL, PostgreSQL, SQL Server, Oracle, SQLite) and generic ANSI SQL. Dialect choice affects keyword recognition, especially around features like specific window functions or proprietary extensions.
Will formatting change query behavior?
No. Formatting only changes whitespace and case. Query semantics are unchanged.
Can I customize the style?
Most formatters offer indent size, keyword case, and comma placement options. For deeper customization (specific keyword positioning, line breaks), specialized SQL editors give more control.
What if my query has syntax errors?
Formatters often partially format syntactically incorrect SQL but may produce confusing output. Fix syntax errors first; format after.
Should keywords be uppercase or lowercase?
Convention varies. Uppercase keywords are traditional and common. Lowercase is gaining adoption in modern style guides. Pick one and stay consistent within the codebase.
Does it format stored procedures?
Most formatters handle stored procedure syntax (CREATE PROCEDURE, BEGIN/END blocks, control flow). Dialect-specific extensions may be partially supported.
Is my SQL uploaded?
No. Formatting happens in your browser.
Can I format from the command line?
Several SQL formatters offer CLI tools (sqlfluff, sql-formatter). Use them for batch formatting or CI integration. Browser formatters are for ad-hoc one-off use.