SQL Formatter - Format and Beautify SQL Online
Format and beautify SQL queries with clean indentation and uppercase keywords, right in your browser.
How to Format SQL - Step by Step Guide
Input Your SQL Query
Let's get your SQL query into the formatter! Whether you're working with MySQL, PostgreSQL, SQL Server, Oracle, or SQLite databases, need to format JSON, or convert data from CSV to JSON, you have several convenient options:
Example: Unformatted SQL Input
Here's what messy, unformatted SQL looks like:
SELECT u.user_id,u.username,u.email,COUNT(o.order_id) AS total_orders FROM users u LEFT JOIN orders o ON u.user_id=o.user_id WHERE u.status='active' GROUP BY u.user_id ORDER BY total_orders DESC;
Automatic Formatting
The magic happens instantly! As soon as you input SQL, the formatter automatically:
Example: Beautifully Formatted Output
The same SQL query, now properly formatted and readable:
SELECT u.user_id, u.username, u.email, COUNT(o.order_id) AS total_orders FROM users u LEFT JOIN orders o ON u.user_id = o.user_id WHERE u.status = 'active' GROUP BY u.user_id ORDER BY total_orders DESC;
Choose Format Options
Customize your output based on your needs! The formatter gives you control over how your SQL appears:
Export Your Formatted SQL
Get your perfectly formatted SQL ready for use! Multiple export options make it easy to integrate into your workflow:
Frequently Asked Questions
How do I format messy SQL queries?
Paste the query into the input editor and the formatted version appears on the right about half a second after you stop typing. Each clause (SELECT, FROM, WHERE, GROUP BY and so on) starts on its own line, columns are indented by two spaces and keywords are written in uppercase.
Does it work with all SQL databases?
It reads standard SQL first. If the query uses syntax only one database understands, such as PostgreSQL $$ bodies and :: casts, SQL Server [bracketed names] or MySQL # comments, it tries the PostgreSQL, MySQL, SQL Server and SQLite rules in turn. Very unusual vendor syntax can still fail, and then you get an error with the line and column instead of a half-formatted query.
Can formatting change what my query does?
It should not. Only spacing, line breaks and the case of SQL keywords change. Text inside quotes, quoted column names, $$ bodies and numbers such as 8901240544102066246, 14.50 or the string 00501 come out exactly as you typed them. Before showing a result the page compares all of those against your input, and if anything differs it shows an error instead.
Can I both format and minify SQL in the same tool?
Yes. The output is formatted by default. Click Minify to put the query on as few lines as possible: whitespace and comments between tokens are removed, while strings and quoted names stay exactly as written. Editing the input switches back to the formatted view.
Can I format SQL files with multiple queries?
Yes. Statements separated by semicolons are formatted one after another with a blank line between them, and you can upload a .sql or .txt file instead of pasting. Everything runs in your browser, so very large files mostly depend on how fast your device is. You can also use our JSON to Table tool to look at query results.
Is the SQL formatter free?
Yes, it is free and needs no account. Your SQL is formatted in the browser and is not sent to our server. For JSON data there is a separate JSON Formatter.
Related: JSON to Table for query results, and the JSON Formatter for JSON data.
Related Tools
SQL Beautifier
Beautify and format SQL code with customizable style options
SQL Fixer
Fix broken SQL queries automatically, repair syntax errors, and validate SQL structure
SQL Minifier
Minify and compress SQL queries by removing whitespace and comments
SQL Validator
Validate SQL syntax and detect errors in your queries
SQL to JSON
Convert SQL query results to JSON format
SQL Compare
Compare two SQL queries side-by-side with diff highlighting