Database & Code

SQL Formatter

Format and beautify messy SQL queries — paste any SQL and get properly indented, readable output for MySQL, PostgreSQL, SQLite and more.

Open SQL Formatter →
Looks like you're using an ad blocker. Devbin is free — ads help keep it running.

Before and After

Before (messy)
select u.id,u.name,o.total from users u inner join orders o on u.id=o.user_id where o.total>100 order by o.total desc
After (formatted)
SELECT u.id, u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id WHERE o.total > 100 ORDER BY o.total DESC

How to Use It

1

Open the tool

Go to Database & Code and scroll to the SQL Formatter.

2

Paste your SQL

Paste the SQL query — it can be minified, from a log file, or typed inline in an ORM call.

3

Format

Click Format to apply keyword uppercase, clause indentation and line breaks.

4

Copy

Copy the formatted SQL for your editor, documentation or code review comment.

Pro Tips

💡Use formatted SQL in code reviews and pull request descriptions — reviewers can read the query logic without running it.
💡When logging slow queries from a database, format them first before debugging to see which clauses might be causing the performance issue.
💡CTEs (WITH name AS (...)) make complex queries easier to read than deeply nested subqueries — the formatter indents them clearly.

Frequently Asked Questions

Does formatting affect SQL performance?
No — formatting only changes whitespace and keyword casing. The database engine ignores formatting when parsing queries.
Should SQL keywords be uppercase?
By convention yes — SELECT, FROM, WHERE, JOIN in uppercase makes queries easier to scan. No database requires it.
Does it work with CTEs and subqueries?
Yes — subqueries and WITH CTEs are indented to show query structure clearly.
Which databases are supported?
Formatting rules for SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY are universal across MySQL, PostgreSQL, SQLite, SQL Server and Oracle.

Format your SQL now

Open the SQL Formatter and turn messy queries into clean, readable SQL — free, no login required.

Open SQL Formatter →