SQL Formatter
Understand SQL Formatter
This formatter puts each SQL clause on its own line, uppercases reserved words, and indents the conditions underneath WHERE.
How it works
It works on the text rather than parsing the query: whitespace is collapsed, keywords from a fixed list are uppercased, a line break is inserted before each major clause — SELECT, FROM, the JOIN family, WHERE, GROUP BY, ORDER BY and the rest — and lines starting with AND, OR, or NOT are indented under the clause they belong to. Longer keywords are matched before shorter ones so LEFT JOIN stays intact instead of breaking at JOIN.
When to use it
- Reading a long query pulled out of an ORM log or a slow-query log.
- Formatting a query for a pull request so reviewers can follow the joins.
- Making the join order in an inherited query visible before you change it.
- Normalizing keyword casing across a file several people have written in.
Watch out for
- String literals are not protected. Because the pass is textual, a keyword inside quotes is rewritten too: WHERE note = 'select one' comes back with SELECT capitalized and a line break inside the string. Read the output before running any query that contains quoted text.
- Formatting is not validation. A query with a syntax error formats cleanly and still fails the moment the database parses it.
- Dialect syntax is passed through but not understood. PostgreSQL $ function bodies, stored-procedure blocks, and vendor-specific statements can end up split across lines in ways that read badly even when they still run.
Not the right tool for: Judging whether a query is correct or fast. Run EXPLAIN against the real database — the formatter knows nothing about your tables.
Frequently Asked Questions
How to format SQL query?
Paste your SQL into the input and click Format. The tool uppercases reserved keywords (SELECT, FROM, WHERE, JOIN), adds proper indentation for nested queries, and places each major clause on its own line. Supports MySQL, PostgreSQL, SQLite, and SQL Server dialects.
Does this work with stored procedures and CTEs?
Yes — the formatter handles multi-statement SQL including CTEs (WITH ... AS), stored procedures, triggers, and subqueries. Each clause gets its own line with consistent indentation for nested SELECT statements.
Can I minify SQL?
Yes — switch to minify mode to collapse the query into a single line with minimal whitespace. Useful for embedding SQL in config files, reducing log noise, or fitting queries in inline strings in application code.
How to Use SQL Formatter
- Paste or type your input in the input area above.
- The tool processes your input automatically or click Run.
- Copy or download the result using the action buttons.
- Use Ctrl+Enter to run quickly from the keyboard.