SQL Formatter
Turn a cramped, one-line SQL query into a clean, readable statement with capitalized keywords and smart indentation — free and instant. Your query is formatted in your browser and never uploaded.
How to use the SQL Formatter
- Paste your SQL. Drop in a query — a minified one-liner, an ORM-generated statement or a hand-written query that has grown messy.
- Choose your style. Pick whether keywords are UPPERCASE, lowercase or left as-is, and select 2-space, 4-space or tab indentation, then press Format SQL.
- Copy or download. Copy the beautified query to your clipboard or download it as a
.sqlfile, ready to drop into a migration or code review.
About this tool
This free online SQL formatter beautifies and pretty-prints SQL so it is easy to read, review and debug. It capitalizes reserved keywords, puts each major clause — SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN and more — on its own line, indents the columns in a select list, breaks AND and OR conditions onto aligned lines, and indents subqueries and common table expressions so the structure of the statement is obvious at a glance.
The formatter tokenizes your SQL first, so text inside quoted strings, double-quoted or back-ticked identifiers and comments is preserved exactly, and the spaces required inside BETWEEN … AND … are handled correctly rather than being split across lines. It works with the common dialects — MySQL, PostgreSQL, SQL Server, SQLite and Oracle — and everything runs locally in your browser, so your queries are never uploaded, logged or stored and the tool works offline once loaded.
Frequently asked questions
Does formatting change what my query does?
No. The formatter only changes whitespace, line breaks and the letter case of recognised keywords. The tables, columns, values, string literals and comments are preserved exactly, so the formatted query returns the same results as your original.
Which SQL dialects are supported?
It handles the keywords and syntax common to MySQL, PostgreSQL, SQL Server (T-SQL), SQLite and Oracle, including joins, subqueries, CTEs (WITH), CASE expressions, UNION and INSERT/UPDATE/DELETE statements. Very dialect-specific extensions are passed through unchanged rather than reformatted.
Will my string literals and comments be preserved?
Yes. The query is parsed into tokens, so anything inside single quotes, double-quoted or back-ticked identifiers, and -- or /* */ comments is copied through verbatim. Only the whitespace and keyword case outside those tokens is adjusted.
Is my SQL uploaded to a server?
No. All tokenizing and formatting happens inside your browser with client-side JavaScript. Nothing you paste leaves your device, so the tool is safe for queries that contain sensitive schema or data, and it works offline once the page has loaded.