How to use SQL Formatter
The SQL Formatter beautifies and reformats SQL queries by adding consistent indentation, capitalising reserved keywords, inserting line breaks between clauses, and aligning columns in SELECT lists. Well-formatted SQL is dramatically easier to read during code review, debug in query analysers, and document in runbooks. The formatter supports multiple dialects including ANSI SQL, MySQL, PostgreSQL, T-SQL (SQL Server), and BigQuery, running entirely in your browser.
- Paste your raw or minified SQL query into the input area.
- Select the SQL dialect from the dropdown (ANSI, MySQL, PostgreSQL, T-SQL, BigQuery, etc.).
- Choose indentation style: 2 spaces, 4 spaces, or tab.
- Select keyword casing: UPPERCASE (most common), lowercase, or Capitalized.
- Click Format to produce the beautified output.
- Copy the formatted SQL or use the Minify button to collapse it back to a single-line version for embedding in strings.
Your data never leaves your device — 100% private processing.
SQL formatting conventions that aid readability
The most widely adopted SQL style places each major clause on its own line (SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT), indented consistently. Expressions within SELECT are each placed on a new indented line with the comma at the start, making it easy to comment out individual columns without touching other lines. Subqueries are indented one extra level relative to the outer query. JOIN conditions follow the JOIN keyword on the next line with an ON or USING clause. Consistent keyword casing (all uppercase is the traditional convention) distinguishes SQL keywords from identifiers at a glance.
| Format | Example |
|---|---|
| Unformatted | select u.id,u.name,o.total from users u join orders o on u.id=o.user_id where o.total>100 order by o.total desc |
| Formatted | SELECT\n u.id\n , u.name\n , o.total\nFROM users u\nJOIN orders o ON u.id = o.user_id\nWHERE o.total > 100\nORDER BY o.total DESC |
SQL dialect differences to watch for
While core DML (SELECT, INSERT, UPDATE, DELETE) is nearly universal across dialects, important differences exist. MySQL uses backtick (`) for identifier quoting; PostgreSQL and ANSI SQL use double quotes ("); T-SQL uses square brackets ([]). String concatenation is || in ANSI/PostgreSQL but + in T-SQL and CONCAT() in MySQL. The LIMIT clause is MySQL/PostgreSQL syntax; T-SQL uses TOP N or OFFSET/FETCH NEXT; Oracle uses ROWNUM or FETCH FIRST N ROWS ONLY. Boolean literals TRUE/FALSE are ANSI and PostgreSQL; MySQL accepts them but T-SQL uses 1/0. Always specify your target dialect so the formatter applies the correct quoting and syntax conventions.
Worked examples
Format a one-liner
Inputs: select id,name from users where id=1
Result: SELECT / FROM / WHERE on separate lines, keywords uppercased
Keyword casing
Inputs: lowercase keywords
Result: SELECT, FROM, WHERE uppercased; identifiers untouched
Minify back
Inputs: formatted multi-line query
Result: single-line query — identical result rows
Glossary
- DML
- Data Manipulation Language — the SQL subset covering SELECT, INSERT, UPDATE, DELETE, and MERGE.
- DDL
- Data Definition Language — the SQL subset covering CREATE, ALTER, DROP, and TRUNCATE for schema objects.
- CTE
- Common Table Expression — a named temporary result set defined with WITH ... AS (...) that simplifies complex queries.
- Window function
- A SQL function (RANK, ROW_NUMBER, LAG, SUM OVER) that operates over a partition of rows without collapsing them into a single output row.
- Execution plan
- The sequence of operations the database engine uses to satisfy a query; formatted SQL is easier to correlate with plan output.
Related reading
Frequently Asked Questions
Why use SQL Formatter?
- Beautify minified or compressed SQL into readable multi-line format with consistent indentation
- Capitalise reserved keywords (SELECT, FROM, WHERE) to distinguish them from identifiers
- Format SQL for MySQL, PostgreSQL, T-SQL, and BigQuery using each dialect's correct syntax
- Minify formatted SQL back to a single line for embedding in strings or API parameters
Common use cases
- Reformat a long ORM-generated one-liner query to read it during a performance investigation
- Clean up a SQL migration script before code review to make each clause's structure visible
- Format a stored procedure body before adding it to a documentation runbook
- Spot a missing JOIN condition in a complex multi-table query by reformatting it
- Normalise formatting conventions before porting a query from SQL Server to PostgreSQL
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Related Developer Tools
Query String ↔ JSON
Parse a URL query string into JSON, or build a query string from JSON. Handles repeated keys as arrays and URL-encoding. Free, instant, in-browser.
JavaScript Minifier
Minify and compress JavaScript online with Terser. Remove whitespace, comments, and dead code, and optionally mangle names to shrink your JS. Free and private.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
XML Formatter
Format and beautify XML online with proper indentation. Pretty print or minify XML and validate basic structure. Free XML formatter in your browser.
CSS Minifier & Beautifier
Minify and beautify CSS code online. Reduce CSS file size by removing whitespace and comments. Free online CSS minifier with instant results.
Regex Tester
Test and debug regular expressions online. See live matches, capture groups, and replace output. Free, private, instant.
Explore all Developer Tools.