SQL Formatter
Paste a SQL query above to format it.
Paste a messy SQL query and get a clean, indented version you can actually read. This formatter puts major keywords (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) on their own lines, indents joins and conditions, and normalizes the spacing, all while leaving your string literals and quoted identifiers exactly as written. It runs entirely in your browser, so nothing you paste is sent anywhere.
How to use
- Paste your SQL query into the input box.
- Pick an indent width (2 or 4 spaces) and how you want keywords cased (uppercase, lowercase, or kept as typed).
- Read the formatted query in the output box, which updates as you type.
- Click Copy to grab the result, or Use result as input to format it again.
- Click Reset to clear everything and start over.
Examples
- Input: select id, name from users where age > 18 order by name. Output puts SELECT, FROM, WHERE, and ORDER BY each on their own line.
- Input with a join: SELECT u.id FROM users u LEFT JOIN orders o ON u.id = o.user_id WHERE u.active = 1 AND o.total > 100. The LEFT JOIN is indented and the AND starts its own line.
- Input with a string literal: select * from t where name = 'GROUP BY test'. The text inside the quotes is preserved exactly and never reformatted.
FAQs
- Is my SQL sent to a server?
- No. The formatter runs fully in your browser using client-side JavaScript. Your query never leaves your device.
- Will it change the meaning of my query?
- No. It only adjusts whitespace, line breaks, and the case of recognized keywords. String literals, quoted identifiers, and comments are kept exactly as you typed them, so the query still does the same thing.
- Does it validate my SQL?
- No. This is a formatter, not a parser or linter. It reformats the text on a best effort basis and does not check that your query is valid or that the tables and columns exist.
- Which SQL dialects does it support?
- It uses a general set of common keywords (SELECT, FROM, JOIN, GROUP BY, and more) that work across most dialects like PostgreSQL, MySQL, SQL Server, and SQLite. Very dialect specific syntax may not be styled, but it will still be preserved.
- Can I keep my keywords in their original case?
- Yes. Choose Keep as typed under the Keywords selector and the formatter will only handle indentation and line breaks, leaving the case of every word untouched.
- Why does a complex query not look perfect?
- This is a heuristic formatter tuned for readability on common queries. Deeply nested subqueries or unusual syntax may format imperfectly, but your original text is never lost.
Related tools
- XML FormatterPretty print XML with clean indentation per nesting level. Pick 2 spaces, 4 spaces, or tabs. Validates broken markup, runs in your browser.
- CSS MinifierMinify CSS online. Strip comments and whitespace, collapse spaces, and shrink stylesheets while keeping strings and url() values intact.
- HTML MinifierMinify HTML in your browser. Remove comments and collapse whitespace while keeping pre, textarea, script, and style content intact.
- Diff CheckerCompare two blocks of text and see what changed, line by line or word by word. Side by side, inline, or unified diff views. Free and private in your browser.
- JSON FormatterFormat, validate, and beautify JSON in your browser. Paste messy JSON, get clean indented output, then copy it back. Free, no signup.
- Base64 EncoderEncode text to Base64 or decode Base64 back to text in your browser. Full UTF-8 support and clear errors on invalid input.