SQL Formatter
How to Use
- Paste or type your SQL query in the input area.
- The formatted output updates in real time.
- Choose keyword casing: UPPER, lower, or preserve original case.
- Adjust indentation (2 or 4 spaces).
- Copy the formatted SQL with the copy button.
SQL Formatting
SQL formatting adds consistent indentation and line breaks to make queries readable. Major clauses (SELECT, FROM, WHERE, JOIN, etc.) start on new lines, and comma-separated items are aligned. This makes complex queries much easier to understand, debug, and review.
Supported Statements
- SELECT queries with JOINs, subqueries, GROUP BY, ORDER BY, HAVING, LIMIT
- INSERT INTO ... VALUES
- UPDATE ... SET ... WHERE
- DELETE FROM ... WHERE
- CREATE TABLE, ALTER TABLE, DROP TABLE
- Comments (-- single line)
Use Cases
- Code review: Format SQL queries consistently so reviewers can quickly understand the logic without deciphering dense one-liners.
- Debugging: Break complex queries into readable parts to isolate issues in JOINs, WHERE conditions, or subqueries.
- Documentation: Include well-formatted SQL examples in wiki pages, README files, or technical specs.
- Learning: Students and beginners can see the structure of SQL clauses laid out clearly.
- Migration scripts: Clean up auto-generated or legacy SQL before committing to version control.
SQL Style Tips
- Use UPPER case for SQL keywords (SELECT, FROM, WHERE) to visually distinguish them from table and column names.
- Place each column in a SELECT list on its own line for easier diffing in version control.
- Indent JOIN and WHERE conditions to show their relationship to the main clause.
- Add comments (-- ) before complex subqueries or non-obvious WHERE conditions to explain intent.
- Keep consistent formatting across your team by agreeing on a style guide and using a formatter.
Privacy
All formatting happens in your browser. No data is sent to any server.
FAQ
What is the difference between SQL formatting and validation?
This tool only formats — it adds indentation and line breaks for readability and does not verify that the query will run. It performs no validation against a schema or database, so a query can format cleanly yet still error at execution time.
Is it safe to paste production database queries?
Yes. All formatting runs entirely in your browser, and the SQL you enter is never sent to, stored on, or logged by any server. You can safely paste production queries containing real table names and values.
Are there SQL statements or dialects it does not support?
It handles SELECT, INSERT, UPDATE, DELETE, CREATE/ALTER/DROP TABLE, and single-line comments (--). Vendor-specific syntax or the complex structure of stored procedures may not format exactly as expected.
How do I control keyword casing?
You can set keywords like SELECT and WHERE to UPPER, lower, or preserve the original case. Uppercasing keywords generally makes them easier to distinguish visually from table and column names.
Can I change the indentation width?
Yes. You can choose between 2 and 4 spaces. Keeping it consistent with your team's style guide makes diffs in version control easier to read.