SQL Formatter & Minifier
Pretty-print SQL with one clause per line, upper-case keywords and indented subqueries, view it with syntax highlighting, or minify it onto a single line.
Why format SQL?
Queries copied from application logs, ORMs or monitoring tools usually arrive as one long line, and hand-written SQL drifts into a mix of cases and indent styles. Laying a query out one clause per line makes joins, filters and grouping easy to review, and makes a diff of two versions much smaller. This formatter reads your SQL, splits it into tokens (keywords, identifiers, strings, numbers, operators and comments) and rebuilds it with a consistent layout. Minify does the opposite and packs a query onto one line for embedding in code, a config file or a command.
How to use it
- Paste one or more statements into Input SQL, or click Sample SQL to load three example queries: a SELECT with a join, subquery and GROUP BY, an INSERT … SELECT, and an UPDATE with a CASE expression.
- Click Format. The result appears under Formatted SQL with keywords, functions, strings, numbers and comments in different colours.
- Click Minify instead to strip comments and collapse whitespace into a single line.
- Check the stats line: number of lines, number of characters and the size ratio compared with your input.
- Click Copy Output to copy the plain text (no colours), or Clear to empty both input and output.
Formatting rules
- SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, SET, VALUES, RETURNING and set operators such as UNION start a new line; UNION ALL is preceded by a blank line.
- Every comma starts a new, indented line, so each selected column or grouped expression gets its own row.
- JOIN variants (INNER, LEFT, RIGHT, FULL, CROSS, with or without OUTER) start a new line, and their ON condition goes on the next line, indented. AND and OR also move to indented lines.
- A parenthesis followed by SELECT or WITH opens an indented subquery block that closes at the matching parenthesis; function-call parentheses such as
COUNT(o.id)stay inline. - CASE expressions indent their WHEN and ELSE branches, each on its own line, and END returns to the outer indentation.
- Recognised keywords and functions are upper-cased. Single-quoted strings, double-quoted and backtick-quoted identifiers and comments are copied exactly as written, and a semicolon ends a statement and resets the indentation.
Limitations
The formatter is rule-based and does not parse SQL grammar, so it never reports syntax errors. The AND in BETWEEN x AND y is moved to its own line like a logical AND, and commas inside function calls also cause line breaks. Column names that happen to be keywords (for example date, year or first) are upper-cased; unquoted identifiers are case-insensitive in most databases, but check if you rely on exact case. Dialect-specific syntax such as PostgreSQL dollar-quoted function bodies or named parameters written as :name may not be laid out cleanly. Formatting and minifying run entirely in your browser with plain JavaScript: queries are not sent to a server and nothing is stored.
Frequently asked questions
Which SQL dialects does it support?
It handles the syntax shared by MySQL, PostgreSQL, SQLite, SQL Server and Oracle: SELECT, INSERT, UPDATE, DELETE, joins, CTEs with WITH, window functions with OVER and PARTITION BY, and CASE. Vendor extensions are passed through but may not get special layout.
Can formatting change what my query does?
It is designed to change only whitespace and keyword case. Strings and quoted identifiers are never touched, and a -- comment always stays on its own line so it cannot swallow the code that follows. Still, review the output before running it against a production database.
What does Minify remove?
Comments (both -- and /* */) and extra whitespace between tokens. Text inside quotes, including runs of spaces, is kept exactly as written.
Is my SQL uploaded or logged?
No. The page does all the work locally, so it is safe for queries that contain table names or sample values you would rather not share. Nothing is saved in your browser either.