Free Online SQL Formatter
Beautify messy SQL queries with configurable indentation.
Formatting uses the sql-formatter library loaded from a CDN. If the CDN is blocked, a lightweight built-in formatter takes over so the tool still works offline.
About the SQL Formatter
SQL is readable when it is consistently laid out, but queries pasted from logs, ORMs, or one-line tickets are often a wall of uppercase and lowercase keywords with no line breaks. This formatter rewrites a query with predictable indentation, one major clause per line, and a keyword case that matches your team's style. It supports standard SQL, MySQL, and PostgreSQL syntax.
Why formatting matters
- Review: a formatted query makes joins, filters, and subqueries easy to scan in code review.
- Debugging: separating clauses helps you isolate a missing condition or a misplaced
AND. - Consistency: a shared style reduces noisy diffs when several people edit the same query.
- Documentation: formatted SQL is easier to paste into runbooks, dashboards, and tickets.
The formatter understands strings, quoted identifiers, backtick identifiers, line comments, and block comments, so keywords inside string literals are left alone. Choose the dialect that matches your database because quoting rules and some constructs differ between MySQL and PostgreSQL. The indent control changes the width of nested blocks, and the keyword case control can uppercase keywords, lowercase them, or preserve the original spelling.
Formatting never changes the meaning of a query: whitespace outside strings and comments is not significant to the database. Always review the result before running a write or delete statement, especially if the original text was truncated. If the remote library cannot be loaded, the built-in fallback still inserts line breaks and indents nested parentheses, but its output is simpler than the full formatter.
How to use this tool
- Paste a query into the input box.
- Select the SQL dialect, indent size, and keyword case.
- The output updates as you type, or click Format SQL to run it again.
- Copy the formatted query or download it as a .sql file.
Frequently asked questions
Does formatting execute my query?
No. The tool is text processing only. It does not connect to a database or run any SQL.
Which dialect should I choose?
Use MySQL for backtick-quoted identifiers and MySQL-specific syntax, PostgreSQL for double-quoted identifiers and PostgreSQL features, and Standard SQL for portable queries.
Is my query sent to a server?
No. The formatter library is downloaded once, then your query is processed locally in the browser.