SQL Formatter
Format, indent, and pretty-print SQL queries instantly. Choose uppercase or lowercase keywords, adjust indent size, or compress to a single line. Your queries never leave your browser.
About SQL Formatting
SQL formatting makes queries readable for debugging, code reviews, and sharing. Formatting helps identify syntax errors and understand query logic at a glance.
🔒 All processing happens locally in your browser.
All processing happens locally in your browser — nothing is stored or sent to any server.
How to Use This SQL Formatter
- Paste your SQL query into the input field.
- Click Format to get a nicely indented, readable query.
- Toggle UPPERCASE or lowercase for keyword style.
- Adjust indent size (2 or 4 spaces) with the dropdown.
- Click Compress for a single-line, production-ready query.
- Use Copy or Load Sample to try it out.
About SQL Formatting
SQL formatting is a crucial practice for anyone working with databases. A well-formatted query makes it easy to identify which columns are selected, how tables are joined, what conditions filter the results, and how the data is sorted. When debugging a slow query, readable formatting lets you quickly spot missing indexes, unnecessary subqueries, or incorrect join conditions.
This formatter handles complex queries including CTEs (Common Table Expressions with WITH), nested subqueries, CASE statements, and multi-table joins. It intelligently places keywords like JOIN, WHERE, and ORDER BY on their own lines for maximum readability.
All formatting is done locally in your browser — your SQL queries are never sent to any server. This makes the tool safe to use even with sensitive or proprietary database queries.
Frequently Asked Questions
What does SQL formatting do? ▼
SQL formatting takes messy, single-line queries and adds proper indentation, line breaks, and spacing. This makes queries easier to read, debug, and share with teammates. A formatted query helps you spot syntax errors, understand query logic at a glance, and maintain consistent code style.
Does the formatter support all SQL dialects? ▼
This formatter recognizes standard SQL keywords used across MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. Keywords like <code>SELECT</code>, <code>JOIN</code>, <code>WHERE</code>, <code>GROUP BY</code>, <code>ORDER BY</code>, <code>WITH</code> (CTEs), and more are all formatted correctly. Dialect-specific functions may not be highlighted but will be preserved.
Can I choose uppercase or lowercase keywords? ▼
Yes. Toggle between UPPERCASE and lowercase keyword styles using the buttons above the output. The formatter preserves case for table names, column names, and string literals.
What does Compress do? ▼
Compress removes all unnecessary whitespace and comments to produce a single-line, production-ready query. This is useful for minimizing query size in API payloads or database requests.
Is my SQL data sent to a server? ▼
No. All formatting happens in your browser using JavaScript. Your queries are never transmitted over the network.
Will the formatter validate my SQL? ▼
No — this is a formatter, not a parser. It tokenizes keywords and applies indentation rules, but it does not check syntax against a specific dialect. To validate, run the query against your database in a safe environment (a SELECT against a non-production schema, or use EXPLAIN to inspect without executing).
Why does my CTE indent unexpectedly? ▼
CTEs are indented as nested blocks inside the <code>WITH</code> clause. If the inner SELECT contains its own subquery or another CTE, the formatter increases indent depth recursively. If the indentation feels too deep, switch to 2-space indent or compress and re-format with a flat structure.
How should I format SQL inside application code? ▼
Use the formatter to get the query right, then either keep it formatted with proper string literals (template literals in JavaScript, raw strings in Python) or compress to a single line for ORM string parameters. Many ORMs accept multi-line strings, but linters and source-control diffs are cleaner with consistent compressed strings.