SQL Beautifier - Beautify and Format SQL Online
Paste a cramped SQL query and get it back with one clause per line, indented columns and uppercase keywords, with every string and number left as written.
How to Beautify SQL Code - Step by Step Guide
Input Your SQL Query
Let's get your SQL query into the beautifier! Whether you're working with MySQL, PostgreSQL, SQL Server, Oracle, or SQLite databases, 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 Beautification & Formatting
You don't need to press anything. About half a second after you stop typing, the tool:
Example: Beautifully Formatted Output
The same SQL query, now properly beautified 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;
Export Your Beautiful SQL
Get your beautifully formatted SQL ready for use! Multiple export options make it easy to integrate into your workflow:
Frequently Asked Questions
What does the SQL beautifier change?
Only the layout. Each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) gets its own line, the columns and conditions under it are indented by two spaces, and SQL keywords are written in uppercase. Comments stay where they were. If you need the opposite, a query squeezed onto as few lines as possible, click Minify or use the SQL Minifier.
Which SQL dialects can it read?
It tries standard SQL first. When a query uses syntax that only one database understands, such as PostgreSQL $$ bodies and :: casts, SQL Server [bracketed names] or MySQL backslash escapes, it falls back to the PostgreSQL, MySQL, SQL Server and SQLite rules in turn. Some vendor-specific syntax, for example Oracle q'[...]' strings, can still fail. In that case you get an error with the line and column rather than a half-beautified query.
Is a SQL beautifier different from a SQL formatter?
Not really, the two names describe the same job. This page is meant for the quick case: someone pasted a 400-character query into a ticket or a chat and you want to read it. Our SQL Formatter uses the same engine and the same rules, so the output is identical on both pages.
Can I beautify a whole script with many statements?
Yes. Statements separated by semicolons are laid out one after another with a blank line between them. You can paste the script or upload a .sql or .txt file. Everything happens in your browser, so a very large migration file mostly depends on how fast your device is.
Will the beautified query still return the same rows?
It should, because only spaces, line breaks and keyword case change. Text inside quotes, quoted column names, $$ bodies and numbers such as 8901240544102066246, 14.50 or the string '00501' are copied exactly. Before showing a result the page compares all of them with your input, and if anything differs, or a quote or /* comment is never closed, it shows an error naming the line and column instead.
Is it free, and is my SQL sent anywhere?
It is free and needs no account. Your SQL is beautified in the browser and is not sent to our server, so it is fine to paste queries that mention internal table names.
Need the reverse? The SQL Minifier compresses queries, the SQL Formatter does the same job as this page, and JSON to Table or the JSON Formatter help once your query results come back as JSON.
Related Tools
SQL Formatter
Format and beautify SQL queries with proper indentation and syntax highlighting
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