SQL Formatter

Paste any SQL query to auto-indent and prettify it. Choose keyword casing, indentation style, and SQL dialect. All formatting happens in your browser — your queries never leave your machine.

Dialect
Keywords
Indent
Commas
Newline before AND/OR
Input · SQL
Output · Formatted SQL
❤️ Support CodeConverter.net and donate ❤️

Everything you need to know about SQL formatting

Why format SQL queries?

Raw SQL from ORMs, query logs, or minified sources is often a single dense line with no whitespace — impossible to read or debug. A well-formatted query makes the SELECT list, JOIN conditions, WHERE clauses, and ORDER BY expressions immediately visible as distinct logical sections. This dramatically reduces the time to understand or modify a query, especially as complexity grows.

Consistent SQL style also matters in team environments. When every developer formats queries the same way — uppercase keywords, 4-space indentation, trailing commas — code reviews focus on logic rather than aesthetics. Many teams enforce SQL formatting in their CI pipelines alongside linting for application code. This free tool handles the formatting instantly so you can focus on writing good queries.

What gets formatted
  • Keywords — SELECT, FROM, WHERE, JOIN on new lines
  • Consistent indentation of sub-clauses and subqueries
  • Column lists with one column per line
  • Logical operators (AND, OR) on their own lines
100% private & client-side
  • All formatting runs inside your browser
  • Zero data transmitted — safe for production queries
  • Paste queries with real table & column names safely
  • Works offline after initial page load
How to use this tool
  • Paste your SQL or click Sample for an example
  • Choose dialect, keyword casing, and indent style
  • Click Format SQL to prettify
  • Copy the result or download as .sql
SQL dialect differences
  • MySQL — backtick identifiers, LIMIT x,y syntax
  • PostgreSQL — double-quote identifiers, ILIKE, CTEs
  • T-SQL — bracket identifiers, TOP, NOCOUNT
  • Dialect choice influences keyword recognition & hints
Keyword casing styles
  • UPPERCASE — traditional SQL style, most common
  • lowercase — preferred in some modern style guides
  • Capitalize — First letter upper, rest lower
  • Preserve — leave keyword casing as-is
Comma placement styles
  • Trailing — comma at end of line (col1,)
  • Leading — comma at start of next line (, col2)
  • Leading commas make diffs cleaner when adding columns
  • Most style guides use trailing — match your team's choice

SQL formatting best practices

Good SQL style is more than just pretty-printing. Capitalising SQL keywords (SELECT, FROM, WHERE) makes them visually distinct from table names and column identifiers, which is the most widely used convention. Placing each major clause on its own line — and indenting the items that belong to it — lets you scan the query structure at a glance. For SELECT lists with multiple columns, one column per line makes it trivial to add, remove, or comment out a column without touching surrounding lines.

For WHERE clauses with multiple conditions, placing AND / OR at the beginning of each new line is common because it draws attention to the logical operator and makes the structure of compound conditions easier to follow. The same principle applies to JOIN conditions with ON. Consistent formatting across your codebase also helps tools like sqlfluff or pgFormatter enforce style in CI pipelines.