Why this matters
SQL queries in production codebases, log files, and ORM-generated output are often minified, single-line strings that are nearly impossible to read. When you are debugging a slow query from a database monitor or reviewing a query built by an application framework, the first step is making it human-readable. Without formatting, spotting a missing JOIN condition, a misplaced WHERE clause, or an extra comma in a column list requires painstaking character-by-character scanning.
This formatter tokenizes the input SQL and applies three transformations: uppercasing all recognized SQL keywords, starting each major clause on a new line with appropriate indentation, and wrapping column lists with line breaks. It preserves string literals, quoted identifiers, and comments verbatim so the semantic content of your query is never altered. The result is a query that follows the readability conventions most database professionals expect, ready for pasting into a documentation file, a code review comment, or an SQL IDE.
Formatting rules applied
| Rule | Detail | Example |
|---|---|---|
| Keyword casing | All SQL keywords uppercased | select becomes SELECT |
| Clause breaks | Major clauses start new lines | SELECT ... FROM ... WHERE |
| AND/OR indent | Continuation conditions indented | WHERE x=1 AND y=2 |
| Column wrapping | Comma-separated lists broken | col1, col2, col3 on new lines |
| String preservation | Single-quoted strings untouched | 'hello world' stays as-is |
| Comment preservation | -- and /* */ comments kept | Verbatim |
| Identifier preservation | Backtick and double-quote kept | `table_name` stays as-is |
How to use it
Paste your SQL query into the input text area — it can be minified, poorly formatted, or copied from a log file.
Click the Format SQL button to process the query.
Review the formatted output in the result panel, which shows proper keyword casing, clause line breaks, and indented conditions.
Click the copy button to grab the formatted SQL and paste it into your editor, documentation, or SQL client.
For queries with syntax errors, the formatter does its best with what it can parse — review the output carefully if the input was incomplete.
Testing your result
Paste a known query like `select u.name, o.total from users u join orders o on u.id=o.user_id where o.total>100 and u.active=1 order by o.total desc` and verify the formatter produces uppercase keywords, each clause on its own line, and the AND condition indented on a continuation line. Check that string values like 'John' and comments like `-- filter` pass through unchanged. Test with a query containing a subquery and confirm the parentheses are preserved even if the subquery is not deeply indented.
Common mistakes
Expecting dialect-specific formatting — the formatter is dialect-agnostic and uses ANSI SQL keyword recognition, so proprietary syntax from specific databases may not be perfectly formatted.
Assuming the formatter validates SQL syntax — it beautifies the text but does not check whether the query is semantically correct or would execute without errors.
Pasting queries with template variables or parameter placeholders (like `:name` or `?`) and expecting them to be treated specially — they are preserved as-is.
Expecting deeply nested subquery indentation — the formatter preserves parentheses and wraps column lists, but subqueries are not indented multiple levels like a hand-formatted query might be.
Relying on the formatter as a linter — it handles cosmetic formatting only and will not catch performance issues, missing indexes, or SQL injection vulnerabilities.
Edge cases and options
The formatter recognizes ANSI SQL keywords plus common DML and DDL statements, which covers the vast majority of queries for MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. Single-quoted string literals, double-quoted identifiers (common in PostgreSQL), and backtick-quoted identifiers (common in MySQL) are tokenized and preserved verbatim. Line comments with `--` and block comments with `/* */` pass through unchanged. The formatter does not add or remove semicolons, so if your input lacks a terminating semicolon the output will too.
Real-world use cases
Developers debugging ORM-generated queries that arrive as single-line strings in application logs.
Database administrators reviewing poorly formatted queries from query monitors or slow-query logs.
Technical writers preparing SQL examples for documentation and ensuring consistent formatting across all code samples.
Code reviewers pasting submitted SQL into a readable format before evaluating query structure and performance.
Frequently asked questions
Q: Which SQL dialects are supported?
A: The formatter is dialect-agnostic. It uppercases recognized ANSI SQL keywords and breaks lines at major clause boundaries. It works well with MySQL, PostgreSQL, SQLite, SQL Server, and Oracle queries, though highly proprietary syntax may not be perfectly formatted.
Q: Which keywords get uppercased?
A: Recognized SQL keywords including SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, INSERT, UPDATE, DELETE, HAVING, LIMIT, and other common DML/DDL keywords. Identifiers, string literals, and comments are left in their original form.
Q: Are string literals and comments preserved?
A: Yes. Single-quoted strings, double-quoted identifiers, backtick-quoted identifiers, line comments (--), and block comments (/* */) are tokenized and output verbatim without modification.
Q: Does the formatter handle subqueries?
A: Parentheses are preserved and comma-separated column lists are wrapped across lines, but subqueries are not deeply indented. The output is readable but may not match the nesting level of a carefully hand-formatted query.
Q: Does it validate SQL syntax?
A: No. The formatter performs cosmetic beautification only. It does not parse or validate the query for correctness. Use your database's query planner or a SQL linter for syntax validation.
Q: Is my query sent to any server?
A: No. All tokenization and formatting happens entirely in your browser.
Start using it now
Try the SQL Formatter tool. See also JSON Formatter, JS Minifier and Beautifier, and CSS Minifier and Beautifier.