Command Palette

Search for a command to run...

SQL

SQL Formatter

Indent and tidy complex SQL so queries stay readable.

Format options
Choose indentation, keyword casing, and line break rules.

Pick tabs or 2/4 spaces; both are common in SQL.

Convert SELECT/FROM/WHERE and JOIN keywords to uppercase.

Place each SELECT column on its own line after commas.

Move AND/OR to new lines inside WHERE/HAVING for scan-friendly filters.

Start JOIN and ON clauses on their own lines to visualize join chains.

Remove spaces at the end of formatted lines.

SQL input
Paste any SQL query to format indentation, clause breaks, and keyword casing.
Supports SELECT/INSERT/UPDATE/DELETE, JOIN chains, CTEs, and CASE blocks.
Formatted SQL
Review and copy the formatted SQL.
Use Select all or Copy to move the result into your editor.

What

SQL Formatter definition

A SQL formatter organizes queries with line breaks and indentation.

Cases

Use Cases

1

Make complex joins readable

2

Review and share queries with teammates

3

Spot syntax issues in long statements

How To

How to Format SQL Queries

A step-by-step guide to making SQL queries easier to read.

1

Paste SQL

Paste your SQL query into the input.

2

Adjust rules

Choose keyword casing and line-break options.

3

Format and copy

Run formatting and copy the formatted SQL.

Knowledge

Understanding SQL Formatting

Why Format SQL?
Formatted SQL is easier to read, debug, and maintain. Consistent formatting helps team members understand complex queries quickly. It also makes version control diffs more meaningful by standardizing whitespace.
Keyword Casing
SQL keywords (SELECT, FROM, WHERE) are case-insensitive but conventionally written in uppercase. This distinguishes keywords from table/column names. Some teams prefer lowercase for a more modern look.
Indentation Strategies
Common approaches: indent after SELECT/FROM/WHERE, align columns, indent JOIN conditions. Right-aligning keywords (SELECT, FROM, WHERE) creates a visual margin. Choose a style and apply it consistently.
Line Breaking
Break lines at logical points: after each SELECT column, before each JOIN, after WHERE/AND/OR. This makes complex queries scannable and helps identify missing conditions or joins.
SQL Dialects
Different databases (PostgreSQL, MySQL, SQL Server, Oracle) have syntax variations. Formatters typically handle standard ANSI SQL. Some dialect-specific syntax may not format perfectly but will remain functional.

FAQ

SQL formatter FAQ

What dialects does this handle?
It is tuned for ANSI-style SQL and works with Postgres, MySQL, and most dialects when queries use standard keywords.
Does it keep string literals untouched?
Yes. Quoted strings and identifiers stay as-is; only keywords and whitespace are adjusted.
How are JOIN chains formatted?
Each JOIN and its ON clause can break onto separate lines to highlight relationships.
Will it uppercase my keywords?
Enable 'Uppercase keywords' to convert recognized clause and join keywords to uppercase.
Can I keep SELECT columns on one line?
Turn off 'Break select columns' to keep comma-separated columns on the same line.
Does it support CTEs?
CTEs that start with WITH go on new lines with indentation preserved for subqueries.
How are AND/OR handled?
Turn on 'Break AND/OR' to put logical operators on new lines for faster scanning.
Will this change semicolons or comments?
Semicolons stay at statement ends; line and block comments are preserved on their own lines.
SQL Formatter