SQL Formatter
About this tool
About SQL Formatter
Paste a one-line query copied from a log, an ORM debug print or a colleague's message and get readable SQL back: every clause on its own line, columns and conditions indented, joins and subqueries lined up. The formatter understands 20 dialects, including PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, Trino and DuckDB, so dialect-specific syntax such as backtick identifiers, square brackets, dollar-quoted function bodies and :: casts is handled correctly. Choose UPPER, lower or as-typed keywords, 2 or 4 spaces or tabs, and whether AND and OR start or end a line. Switch to Minify to squeeze a query onto one line for a config file or a code string; comments are removed but text inside quotes is never touched. Several statements separated by semicolons are formatted in one go. Queries often contain table names and customer data, so everything runs in your browser and nothing is uploaded. Optional AI help can explain what a query does or fix syntax errors, using your own AI key; only the query is sent, straight to your provider.
Built and maintained by Abhi JainUpdated
How to Format SQL
- 1
Paste your SQL
Paste one or more statements into the SQL pane, open a .sql file, or click Sample.
- 2
Pick dialect and style
Choose the Dialect your database uses, then set Keywords (UPPER, lower or As typed) and Indent. Choose Minify instead to get one line.
- 3
Copy or download
The formatted SQL appears on the right as you type. Copy it or download it as a .sql file.
SQL Formatter: questions and answers
Why does the formatter say it could not parse my query?
Each database has its own syntax. Backtick identifiers need MySQL, MariaDB or BigQuery, square brackets need SQL Server, and $$ function bodies need PostgreSQL. Pick the dialect your database uses and check the line and column in the message for a typo.
Should SQL keywords be upper case?
SQL is case-insensitive for keywords, so it is a style choice. Upper-case keywords are the most common convention because they separate SELECT, FROM and WHERE from table and column names at a glance. Many teams use lower case for a calmer look; pick one and stay consistent.
Does formatting change what my query does?
No. Only whitespace, line breaks and, if you choose, the case of keywords change. Table names, column names and string values are kept exactly as written, so the query returns the same result.
Can I format several queries at once?
Yes. Paste a whole script; statements separated by semicolons are formatted one after another with a blank line between them.
Is it safe to paste production queries?
Yes. The formatter runs entirely in your browser. Queries, table names and any values in them are never sent to a server.
Can AI explain or fix my SQL?
Yes, optionally. Connect your own Claude, OpenAI, Gemini, DeepSeek, OpenRouter or compatible key in AI settings, then use the AI button to explain a query or fix syntax errors. Only the SQL in the input (and the formatter's error) is sent, directly from your browser to your provider; formatting itself never needs AI.
Ready-made SQL Formatter presets
Related Tools
- JSON FormatterBeautify, minify and validate JSON with exact error locations, without changing a single value.
- YAML Formatter & ValidatorValidate YAML with line and column errors, re-indent it and keep comments.
- XML FormatterPretty-print, minify and validate XML with line and column errors.
- JavaScript FormatterBeautify minified JavaScript, or minify it safely by removing comments and whitespace.