SQL Formatter
Formatted SQL
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.