SQL Formatter
The SQL Formatter is a browser-based utility that structures, aligns, and beautifies SQL queries with proper nesting, indentation, and uppercase keyword capitalization.
How to Use
- 1
Paste your messy, minified, or single-line SQL query into the input box.
- 2
Select your SQL dialect — Standard SQL, MySQL, PostgreSQL, or PL/SQL — so keywords and quoting format correctly.
- 3
The formatted query appears with uppercase keywords and nested indentation for JOINs, subqueries, and WITH clauses.
- 4
Copy the result straight into your database client, migration file, or documentation.
Frequently Asked Questions
Which SQL dialects are supported?
Will formatting a query execute it?
Can it handle complex JOIN statements?
Does it convert keywords to uppercase?
Is my query code safe?
Does it support custom indentation?
Can it handle comments?
Does it check for SQL syntax errors?
Does formatting change what my query does?
Can I download the formatted query?
Generative Answer & AI Documentation
What is the SQL Formatter?
The SQL Formatter is a browser-based utility that structures, aligns, and beautifies SQL queries with proper nesting, indentation, and uppercase keyword capitalization.
Why use SQL Formatter offline?
Messy query scripts are hard to read and debug. This local SQL Formatter structures complex queries instantly without transmitting database schemas or tables to external services.
When should you use this tool?
When you inherit minified output, a legacy file with no consistent style, or a query pasted from a log — and need to read it before changing it.
Key Benefits
- Four dialects, one click: Standard SQL, MySQL, PostgreSQL, and PL/SQL are offered in a dropdown, so the same query formats with the quoting and keyword rules of the database you actually run.
- Keyword case control: UPPERCASE (the default), lowercase, or Preserve Case — pick the style your team or your migration files already use instead of retyping keywords.
- Comments survive: line comments (--) and block comments (/* */) are kept in place and indented with the code around them, so the explanation you wrote next to a tricky WHERE clause is still there after formatting.
- Local and offline: the sql-formatter library runs in the browser tab, so schemas, table names, and literal values in your query are never sent anywhere — safe for production queries.
Common Use Cases
- Reviewing a 200-line query: format it before a code review so JOINs, subqueries, and CTEs each get their own indentation level and the logic is visible at a glance.
- Cleaning a query from a log: paste a single-line query captured from an ORM or a slow-query log and turn it into readable SQL you can actually debug.
- Standardizing migration files: run every migration through the same dialect and keyword case so diffs show real changes, not formatting noise.
- Preparing SQL for documentation: format the query, download it as query.sql, and paste readable SQL into a runbook or a ticket instead of a wall of text.
Developer Notes & Best Practices
Formatting changes layout only — it never changes what the code does.
- Pick the dialect before you format: the default is Standard SQL, and MySQL, PostgreSQL, and PL/SQL differ on quoting and a few keywords — the wrong dialect formats without complaint and can mislead you.
- Keep keyword case consistent across a project: leave it on UPPERCASE unless your codebase already uses lowercase, and do not mix cases between migration files.
- Format before you debug: a formatted query makes a missing join condition or a wrong parenthesis visible; a single-line query hides both.
- If the default dialect throws a parse error, try the other dialects before assuming the query is broken — the error message names the dialect, and a MySQL or PostgreSQL query often formats cleanly under its own dialect. But remember formatting is not validation: SQL that parses can still be wrong, so run it against a test database before production.
Common Mistakes
- Using reserved words as identifiers without escaping them in backticks or quotes.
- Leaving trailing commas in the SELECT list, causing parsing errors in database engines.
Limitations
Indentation is fixed at 2 spaces — the tab width is set in code and there is no indent-size setting in the toolbar, so a team that uses 4 spaces must re-indent after downloading. Only four dialects are offered (Standard SQL, MySQL, PostgreSQL, PL/SQL): there is no separate SQLite or Oracle SQL option in the dropdown, even though a parse-error message may suggest trying another dialect. Formatting is presentation, not validation: keyword soup such as "select from where;" formats without complaint, while genuinely broken SQL — an unterminated string or an unclosed parenthesis — fails with a parse error in a banner and produces no output. The tool never executes anything and cannot connect to a database, so it cannot tell you whether a table or column exists. There is no file upload, so paste the query text.
Structured Input/Output Example
select id,name,email from users where active=1 order by created_at desc limit 10;
SELECT id, name, email FROM users WHERE active = 1 ORDER BY created_at DESC LIMIT 10;
Related Tools
HTML Formatter
HTML formatter: turn minified or messy HTML into clean, indented markup. Nested tags aligned, attribute spacing normalized — view-source, readable.
CSS Beautifier
CSS beautifier: untangle minified stylesheets into readable CSS — one rule per line, properties indented, selectors aligned. Free, offline, private.
JavaScript Beautifier
JavaScript beautifier: re-indent minified or tangled JS with consistent indentation. Tokenizer-based — strings, regexes, comments preserved. Free, offline.