SQL Formatter
Beautify and indent messy or minified SQL queries.
Formatted SQL will appear here…Paste a minified or inconsistently formatted SQL query and get it back cleanly indented, with each clause on its own line - formatted instantly in your browser.
What is SQL Formatter?
SQL queries are frequently written or generated in a single dense line - copied from an ORM's debug log, minified for an API call, or just typed quickly without much thought for layout. That's fine for a database engine, which doesn't care about whitespace at all, but it's hard for a person to read, especially once a query has several joins, conditions, or a subquery.
Formatting a query means putting major clauses - SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, and so on - each on their own line, indenting column lists and conditions consistently, and generally making the query's structure visible at a glance rather than buried in a wall of text.
This tool handles the common SQL statements - SELECT, INSERT, UPDATE, DELETE - including joins and multi-condition WHERE clauses. It's a practical formatter rather than a full SQL parser, so unusually complex or vendor-specific syntax may not format perfectly in every case.
How It Works
Paste your SQL
Paste a minified or messy SQL query into the input box.
Choose formatting options
Set the indent size and whether keywords like SELECT and WHERE should be uppercase or lowercase.
Copy the formatted result
The formatted query updates instantly; copy it to your clipboard when you're happy with it.
Features
Clause-by-clause formatting
Major clauses like SELECT, FROM, WHERE, JOIN, and ORDER BY are each placed on their own line.
Indented column and condition lists
Column lists and multi-condition clauses are indented consistently for readability.
Keyword casing options
Choose whether SQL keywords are rendered in UPPERCASE or lowercase.
Minify option
Collapse a formatted query back down to a single compact line when you need it for a config value or API call.
Common Uses
Reading a query pulled from a log
Format a minified query copied from a slow-query log or an ORM's debug output to actually understand what it's doing.
Cleaning up a query before a code review
Format a hand-written query consistently before committing it, so reviewers can follow its structure easily.
Documenting a query
Format a query for inclusion in documentation or a wiki page where readability matters.
Preparing a query for an API payload
Minify a formatted query back down to one line for embedding in a config file or API request body.
Why Use Our SQL Formatter?
Formatting happens entirely in your browser - queries are never sent to a server, which matters since SQL often reveals details about your database schema or business logic.
Nothing pasted here is retained after you navigate away from the page.
Tips
- This formatter handles common SQL well but isn't a full parser - for very complex nested subqueries, double-check the result rather than assuming perfect formatting.
- String literals (anything in quotes) are left untouched, so formatting never accidentally changes the meaning of a query.
- Use the minify option when you need to paste a query into a place that expects a single line, like a JSON config value.