SQL Formatter
Format SQL queries for 16 dialects including MySQL, PostgreSQL, SQL Server, Oracle and BigQuery. Choose keyword case and indentation. Runs in your browser.
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is SQL Formatter?
The SQL Formatter rewrites SQL with each clause on its own line and its contents indented, making long queries readable. Pick the dialect so vendor-specific syntax (backticks, :: casts, TOP, QUALIFY…) is understood, and choose upper, lower or preserved keyword case.
How to use SQL Formatter
- Select the SQL dialect (for example MySQL or PostgreSQL).
- Choose Keyword case and Indentation.
- Paste your query into the input box.
- Click Format (the output also updates while you type) and copy the result.
Example
select id,name from users where active=1 order by name
SELECT id, name FROM users WHERE active = 1 ORDER BY name
Dialect MySQL, keywords UPPERCASE, 2 spaces.
When to use SQL Formatter
Use it for reading queries from logs or ORMs, preparing SQL for code review or documentation. It does not validate table or column names and does not execute anything. Procedural code (PL/SQL blocks, T-SQL procedures) is formatted on a best-effort basis.
How SQL Formatter works
Formatting is done by the sql-formatter library. It tokenizes the query with the selected dialect's rules (quotes, comments, parameters, operators), parses it into clauses and expressions, then prints SELECT, FROM, WHERE, JOIN, GROUP BY and other clauses on separate lines with their items indented. Keyword case is applied only to reserved words; identifiers and string literals are never changed. Parse errors show the line and column.
Common Use Cases
- Reading a long one-line query from an application log
- Formatting SQL generated by an ORM
- Applying uppercase keywords before code review
- Preparing readable SQL for documentation
Security Note
Everything runs locally in your browser; the code you paste is not uploaded.
FAQs
Which dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, Hive, Trino, DuckDB, ClickHouse and Db2.
Does it change my identifiers?
No, only keyword case is changed when you ask for it.
Does it check that tables exist?
No, it only formats text.