πŸ—„οΈ SQL Formatter

Beautify messy SQL queries into clean, readable format.

Input SQL
Formatted SQL

How to Use This Tool

Paste any SQL query into the input box, including minified single-line queries from application logs or ORM output. Click Format to get a properly indented, keyword-uppercased result. The Minify option collapses it back for embedding in code strings.

1

Paste your SQL into the Input SQL box, or click Load Example to start with a sample query.

2

Choose your options: uppercase keywords and indent size (2 or 4 spaces).

3

Click Format / Beautify to produce the formatted output in the right panel.

4

Copy the output or use Minify to collapse the query back to a single line.

SQL Formatting Conventions That Matter in Practice

The SQL community has converged on a set of formatting conventions that make queries significantly easier to read and review. Uppercasing reserved keywords (SELECT, FROM, WHERE, JOIN, GROUP BY) visually separates SQL syntax from table and column identifiers, which is especially helpful in editors that do not syntax-highlight SQL. Placing each major clause on its own line and indenting column lists under SELECT makes it easy to see what data you are pulling without scanning a long horizontal string. When a query has multiple JOINs, each JOIN condition on its own indented line makes the relationship structure obvious at a glance. Minified SQL comes from ORMs, query builders, and database logs, and it is nearly unreadable in that form. Pasting ORM-generated output like select u.id,u.name,o.total from users u left join orders o on u.id=o.user_id where u.active=1 into this formatter produces clean, reviewable code in seconds. For code reviews, always paste formatted SQL so reviewers can spot logic errors in JOIN conditions and WHERE clauses without reformatting manually.

Common Use Cases

Reading ORM query outputFormat Eloquent, ActiveRecord, or Hibernate generated SQL for debugging
Code review prepBeautify migration files or stored procedures before submitting a pull request
DocumentationFormat example queries in README files and technical specifications
Minifying for app codeCollapse multi-line SQL to a single string for embedding in PHP, Python, or JS

Frequently Asked Questions

Which SQL dialects does this support?

The formatter handles standard SQL syntax used in MySQL, PostgreSQL, SQLite, and Microsoft SQL Server for common DML/DDL statements.

Does formatting change my SQL logic?

No. Only whitespace and capitalization are adjusted. The logic, table names, column names, and conditions are preserved exactly.

What does keyword uppercasing do?

Capitalizing SQL keywords (SELECT, FROM, WHERE) is a widely adopted convention that improves readability by distinguishing keywords from identifiers.

How do I minify SQL?

Use the Minify button to collapse SQL to a single line β€” useful for embedding queries in application code strings.

Does this handle subqueries?

Yes, basic subquery formatting is supported. Complex nested queries will indent the subquery block for clarity.