SQL Formatter
Beautify or minify SQL queries — format keywords and clauses onto clean lines, in your browser.
Suggested tools
About SQL Formatter
SQL Formatter makes long queries readable: keywords are uppercased and major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY…) start on their own lines. Minify does the opposite, putting a query on one compact line and removing comments.
String literals and quoted identifiers are never changed, so values like 'Select me' stay exactly as written. It works with the standard SQL used by MySQL, PostgreSQL, SQL Server, SQLite and Oracle. It runs entirely in your browser, so nothing you paste is uploaded.
How to use SQL Formatter
- Paste your SQL query.
- Press Format or Minify.
- Copy the result.
Key features
- Keywords uppercased, clauses on new lines
- Minify to a single line
- String literals and quoted names untouched
- Works with common SQL dialects
Example
Keywords are uppercased and each clause starts on a new line; the string 'paid' is untouched.
select u.id, u.name, sum(o.total) as spent from users u join orders o on o.user_id = u.id where o.status = 'paid' group by u.id, u.name order by spent desc
SELECT u.id, u.name, sum(o.total) AS spent FROM users u JOIN orders o ON o.user_id = u.id WHERE o.status = 'paid' GROUP BY u.id, u.name ORDER BY spent DESC
When to use SQL Formatter
- Making a long query from logs or an ORM readable before debugging it.
- Formatting queries consistently for code review.
- Compacting a query to one line for a config file or a script.
Tips and common problems
- Formatting never changes string literals such as 'paid' or quoted column names.
- Minify removes comments, so keep a formatted copy if comments matter.
- Run the formatted query in your database client to check it — formatting does not validate SQL.
Frequently asked questions
No. Only whitespace and keyword case change; SQL keywords are case-insensitive.
A -- comment runs to the end of the line, so on a single line it would comment out the rest of the query.
No, it formats the text. Run the query in your database to check it.