About the SQL Formatter
What is a SQL formatter?
A SQL formatter takes a query that has grown into an unreadable single line — or been copied out of a log, an ORM, or someone else's script — and lays it out the way you'd want to read it: one clause per line, indented subqueries, aligned JOINs, and consistent keyword casing. This one formats live as you type, understands eight dialects from MySQL to BigQuery, and can uppercase, lowercase, or preserve your keywords.
It's powered by the well-established sql-formatter library, bundled locally with this page — nothing loads from a CDN and your queries never leave the browser, which matters when they contain table names and business logic you'd rather not paste into random websites. Because the library genuinely parses SQL, malformed queries produce a clear error badge instead of scrambled output.
How to Use This Tool
- Add your query. Paste SQL into the left editor, open a
.sqlfile, or click Sample. - Pick your dialect. Standard SQL works for most queries; switch to MySQL, PostgreSQL, T-SQL and friends when you use dialect-specific syntax.
- Choose the style. UPPERCASE keywords (the classic), lowercase, or leave them as typed — plus 2-space, 4-space, or tab indentation.
- Take the result. Copy it or download it as a
.sqlfile.
Common Use Cases
- Reading ORM output: Format the single-line monsters your framework generates so you can actually review them.
- Debugging slow queries: A formatted query makes it far easier to spot the missing join condition or the accidental cross join.
- Standardizing a codebase: Bring every query to the same keyword case and indentation before review.
- Learning from logs: Clean up queries captured from slow-query logs and profilers.
- Preparing documentation: Make examples presentable for wikis, tickets, and tutorials.
Building queries visually? Try the SQL Query Builder, generate DDL with the SQL Table Generator, or convert data with SQL to JSON.
Frequently Asked Questions
Which SQL dialects are supported?
Standard SQL plus MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, and BigQuery. The dialect affects how identifiers, operators, and dialect-specific keywords are parsed, so pick the one that matches your database when your query uses vendor syntax.
Does formatting change what the query does?
No. Formatting only rearranges whitespace and, if you choose, the letter case of keywords — which SQL treats as case-insensitive anyway. Identifiers, strings, and values are untouched, so the query executes identically.
Why do I get an error instead of formatted output?
The formatter genuinely parses your SQL, so syntax it cannot parse — a missing parenthesis, a dangling comma, or dialect syntax under the wrong dialect setting — produces an error badge. Check the dialect first; T-SQL and PL/SQL constructs often fail under Standard SQL.
Can it format multiple statements at once?
Yes. Paste a whole script with semicolon-separated statements and each one is formatted in sequence.
Should keywords be uppercase?
It's convention, not requirement: uppercase keywords make the query's skeleton stand out from identifiers and remain the most common house style. The formatter defaults to UPPERCASE but happily produces lowercase or leaves the casing exactly as you typed it.
Are my queries uploaded anywhere?
No. The formatting library is bundled with the page and runs locally in your browser — no CDN calls, no server processing, no logging — and works offline once loaded.