SQL Formatter & Beautifier
Paste a SQL query to pretty-print it with syntax highlighting, or minify it down to one line. Runs entirely in your browser.
Last updated
Input
Options
Run
Formatted or minified SQL will appear here.
How to format a SQL query
- Paste your SQL query.
- Choose the indent size and whether keywords are UPPERCASE or lowercase.
- Click Format to lay it out, or Minify to put it on one line, then Copy result.
About this tool
This is a generic, keyword-aware SQL formatter — it tokenizes your query (strings, numbers, comments, identifiers, and roughly 90 common SQL keywords, including multi-word ones like GROUP BY, LEFT OUTER JOIN, and IS NOT) and lays it out using standard beautifier conventions: major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, and so on) each start a new line, column and argument lists break one item per line, AND/OR get their own indented line, and subqueries in parentheses are indented one level deeper. It is not a real SQL parser for any specific database — it doesn't validate syntax or understand dialect-specific extensions, and a few constructs (parenthesized boolean groups, complex CASE expressions) are simplified rather than perfectly reflowed. For genuinely broken or dialect-exotic SQL, treat the output as a best-effort layout rather than a guarantee.
Minify strips comments and collapses all whitespace to the minimum needed to keep tokens apart, for the smallest possible query string. The keyword case toggle (uppercase/lowercase) and indent size (2 spaces, 4 spaces, or a tab) apply to formatting; identifiers, string contents, and comments are always left exactly as you typed them. Nothing you paste here is sent anywhere — the whole tool runs as JavaScript in your browser tab.
Questions about formatting SQL
How is the query laid out?
Each main clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) starts a new line, columns go one per line, AND and OR get their own lines, and subqueries are indented.
Does it check my SQL for errors?
No. It lays out the query but doesn’t validate it against a database, so very unusual or broken SQL is formatted as well as it can be.
Which databases does it work with?
Standard SQL as used by MySQL, PostgreSQL, SQL Server, SQLite and Oracle. Database-specific extensions may not be laid out perfectly.
Will it change my table names or strings?
No. Only keyword case and spacing change; names, strings and comments stay exactly as you typed them.