SQL Formatter
Format and beautify SQL queries with proper indentation and styling.
Why I Made This SQL Formatter
I spent years looking at one-line SQL queries from logs and debugging minified queries pasted into Slack. Every time someone shared a query, I'd have to manually add line breaks to understand what it was doing. This formatter exists because I got tired of that. Paste messy SQL, get readable SQL. I also needed something that works entirely in the browser - I don't want to send production queries to some random server.
What This Formatter Does
- Smart Indentation - Adds line breaks at the right places so I can actually read the query
- Keyword Case - I prefer uppercase keywords (SELECT, WHERE) for visibility
- Minification - Sometimes I need to go the other way and compress queries for logs
- Dialect Support - Works with MySQL, PostgreSQL, SQLite, and standard SQL
- String Safety - Formatting never touches the contents of string literals
I pair this with the Diff Checker when reviewing query changes and the JSON Formatter when working with query results.
What I Actually Use It For
- Query Debugging - SELECT, JOIN, WHERE, GROUP BY - formatting makes the logic visible
- Migration Scripts - INSERT, UPDATE, DELETE statements that need review
- Schema Changes - CREATE, ALTER, DROP statements before running them in prod
- Transaction Blocks - BEGIN, COMMIT, ROLLBACK - easier to verify nothing's missing
- CASE Expressions - These get deeply nested, formatting makes them manageable
Related Articles
- SQL Formatting Best Practices for Readable Queries
- SQL Injection Prevention: Escaping vs Parameterization
Frequently Asked Questions
Why format SQL queries?
Because nobody can read a 500-character one-liner. I've debugged enough production issues to know that the first step is always "make the query readable." Proper formatting shows the structure - you can see which tables are joined, what conditions apply, how things are grouped. It turns a wall of text into something logical. For dialect-specific syntax, check the PostgreSQL or MySQL docs.
Does this validate my SQL?
Nope, it just formats. I could have a completely broken query, and this will still make it look pretty. For actual validation, you need to run it against a database. This tool is about readability, not correctness.
Are my queries stored or sent to a server?
No - everything runs in your browser. This was non-negotiable for me. I work with production data, and I'm not pasting real queries into some third-party service. Your SQL stays on your machine. Check the network tab if you don't believe me.