SQL Formatter
Format and beautify SQL queries.
How to Use SQL Formatter
Paste your query into the box, including a stored procedure body or a WITH clause if you have one.
Pick a dialect hint and a keyword casing style, either lower case or upper case.
Click the "Process" button to rebuild the query with one clause per line and aligned indentation.
Copy the formatted SQL or download it for a migration, doc block, or code review comment.
Features
Frequently Asked Questions
Related Tools
JSON Formatter
Format and beautify JSON data with proper indentation.
JSON Validator
Validate JSON data and find syntax errors.
JSON Minifier
Minify JSON by removing whitespace and formatting.
HTML Formatter
Format and beautify HTML code.
HTML Minifier
Minify HTML code to reduce file size.
CSS Formatter
Format and beautify CSS code.
About SQL Formatter
Long queries in a log file or a saved report are close to unreadable. Six JOINs with the same three-line WHERE clause repeated in each subquery, all lowercase, all on one line. The SQL Formatter rebuilds the statement so each clause starts on its own line, with indentation that reflects how deeply nested you are.
SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT are broken out one per line, subqueries are indented inside their parentheses, and common table expressions are offset so the main query at the bottom is easy to find. Reserved keywords can be uppercased or lowercased to match your team convention.
What it does not touch matters just as much. String literals, quoted identifiers, and comments come through byte for byte, so a query containing a regex in a string or an escaped quote is not corrupted. No identifiers are renamed and no clause is reordered, so you can run the formatted query against your database and get the same plan and the same rows.
When to Use This Tool
- Reading a query copied out of application logs before opening an issue
- Cleaning up a generated report query before adding it to a migration
- Formatting SQL for documentation, runbooks, or a blog post
- Reviewing a complex query in a pull request that changed only one condition
- Standardising ad-hoc queries written during an incident