SQL formatter
Turn messy SQL into clean, readable queries.
Runs in your browser. Nothing you type is sent anywhere.
- 6 SQL dialects
- Upper or lower keywords
- Nothing uploaded
How to format SQL
- Paste your SQL query.
- Pick a dialect, keyword case and indent size.
- Copy or download the formatted SQL.
Dialect differences this handles
| Dialect | Quirk it accounts for |
|---|---|
| MySQL | Backtick-quoted identifiers |
| PostgreSQL | Double-quoted identifiers and :: type casts |
| SQL Server | Square-bracket identifiers and TOP instead of LIMIT |
| SQLite | More permissive quoting rules |
| BigQuery | Backtick-quoted table paths like project.dataset.table |
| Standard SQL | ANSI-style double-quoted identifiers, the default target |
What formatting changes, and what it leaves alone
- Changes: keyword case, indentation of clauses and joins, and where line breaks fall before SELECT, FROM, WHERE and JOIN.
- Leaves alone: table and column names, string literal contents, and any comments in the query.
- Comments written with -- or wrapped in /* */ stay exactly where they were, attached to the same line or block.
Tips for formatting SQL
- Paste several statements separated by semicolons and each one formats in place.
- Pick the dialect your database actually runs, so identifier quoting in the output matches what your server expects.
- If a dialect's quoting style causes an error in your database, try Standard SQL and adjust identifiers by hand.
- A larger indent size can make a long query with many joins easier to scan, since each nesting level stands out more.
SQL formatter FAQ
Which SQL dialects are supported?
Standard SQL, MySQL, PostgreSQL, SQL Server, SQLite and BigQuery. Each one handles quoting and functions slightly differently.
Does this check whether my SQL is correct?
No. It reformats the query for readability. It does not connect to a database or validate table and column names.
Can I format a whole file of queries at once?
Yes. Paste multiple statements separated by semicolons and each one is formatted in place.
What does the indent size control?
It sets how many spaces each level of nesting gets, from 2 for compact queries up to 8 for deeply nested joins and subqueries.
Is my SQL uploaded anywhere?
No. Formatting happens in your browser, so your queries and any data in them stay on your device.
Does formatting reorder my query?
No. Clauses, joins and subqueries stay in the order you wrote them. Only indentation, line breaks and keyword case change.
Can it format stored procedures or scripts with variables?
Plain SELECT, INSERT, UPDATE and DELETE statements format well. Dialect-specific procedural syntax, like T-SQL control flow or PL/pgSQL blocks, may not indent as cleanly, since the formatter targets standard query syntax.
Does it handle CTEs (WITH clauses) and window functions?
Yes. Common table expressions and window functions format the same as any other syntax the underlying sql-formatter library understands, including their own indentation.