SQL formatter/beautifier
Format messy SQL into clean, indented, readable queries. Great for debugging, code reviews and documentation. Works with MySQL, PostgreSQL and more. Free.
Make SQL readable again
SQL copied from logs, ORMs, BI tools or a colleague's message often arrives as one long line: select u.id,u.name,count(o.id) from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id order by 3 desc. The SQL formatter breaks it onto separate lines, puts each clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) in its place and indents it so you can follow the logic.
Readable SQL is easier to debug, review and document. Spotting a missing join condition or a misplaced WHERE is much faster when the query is laid out properly.
It works with standard SQL as used by MySQL, MariaDB, PostgreSQL, SQLite, SQL Server and others.
How to use the sql formatter/beautifier
- Paste your SQL query.
- Submit to beautify it.
- Read or copy the formatted SQL.
Examples
A one-line report query
Input:
select u.id, u.name, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id, u.name order by orders desc limit 10
Output:
select
u.id,
u.name,
count(o.id) as orders
from
users u
left join orders o on o.user_id = u.id
where
u.active = 1
group by
u.id,
u.name
order by
orders desc
limit
10
Each clause gets its own line and each column is indented. Keywords keep the case you typed.
An update
Input: UPDATE products SET price = price * 1.1 WHERE category_id IN (3, 7);
Output:
UPDATE
products
SET
price = price * 1.1
WHERE
category_id IN (3, 7);
Common uses
- Reading queries captured from application logs or ORM debug output.
- Preparing SQL for code reviews and pull requests.
- Writing documentation and tutorials with clear examples.
- Debugging long queries with many joins and subqueries.
- Tidying queries before saving them in a BI tool or notebook.
- Reading queries copied from application logs, where they're often on one line.
Tips and things to know
- Formatting only changes whitespace. It doesn't validate the SQL or change results.
- Remove real customer data and passwords from queries before pasting them anywhere online.
- Pick a consistent style for your team, such as uppercase keywords and one column per line.
- Change identifier styles with the case converter, and format JSON results with the JSON beautifier.
Edge cases and limitations
- Keywords aren't uppercased. If your team style uses uppercase keywords, type them that way.
- Several statements separated by semicolons are formatted one after another.
- Comments are kept. Strings and quoted identifiers aren't changed.
Frequently asked questions
Does formatting change what my query does?
No. Only spacing and line breaks change, so the query returns the same results.
Which SQL dialects are supported?
Standard SQL keywords used by MySQL, PostgreSQL, SQLite, SQL Server and similar databases format well.
Does it check my SQL for errors?
No. It formats the text; run the query in your database to check for errors.
Should SQL keywords be uppercase?
It's not required, but uppercase keywords are a common convention that makes queries easier to scan.
Related tools
- JSON validator & beautifier: Validate JSON content and make it looks good.
- Case converter: Convert your text to any kind of text case, such as lowercase, UPPERCASE, camelCase, etc.
- JS minifier: Minify your JS by removing all the unnecessary characters.
- HTML entity converter: Encode or decode HTML entities for any given input.
- Text separator: Separate text back and forth by new lines, commas, dots, etc.
Popular free tools
Convert text to UPPERCASE, lowercase, Sentence case, Capital Case, camelCase, PascalCase, snake_case, CONSTANT_CASE, dot.case or param-case. Free.
Look up the DNS records of any domain: A, AAAA, CNAME, MX, NS, TXT and SOA. Check email, SPF, verification and nameserver settings for free.
Create strong, random passwords in one click. Pick the length and include uppercase, lowercase, numbers and symbols. Free, no signup.
Encode any text or string to Base64 instantly. Useful for data URIs, HTTP Basic auth headers, email and APIs. Free online Base64 encoder.
Convert numbers into words, such as 1,250 to “one thousand two hundred fifty”. Write checks, invoices, legal documents and lessons correctly. Free.
Turn normal text into elegant 𝓬𝓾𝓻𝓼𝓲𝓿𝓮 letters you can copy and paste into Instagram, TikTok, X and Discord bios, captions and names. Free.