SQL Formatter
Format and minify SQL for PostgreSQL, MySQL, SQLite, SQL Server, Oracle, BigQuery and Snowflake.
Only spacing and the case of keywords change; your query is not run or checked against a database. Your SQL stays in this browser.
Runs in your browser. Nothing is uploaded.
What is SQL Formatter?
A SQL formatter takes a query that is squeezed onto one line, or written in a mix of styles, and lays it out so you can read it. Each clause starts on its own line, columns are listed one per line, joins and conditions are indented, and keywords are written in one case. The meaning of the query does not change, only the spacing and the letter case of keywords.
Paste your SQL, choose your database in the Dialect box, and the formatted query appears next to it. Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery and Snowflake are supported, because each has its own quoting, operators and functions. You can set the indent, the case of keywords, where AND and OR go, how long a bracketed expression may be before it is split, and whether the semicolon gets its own line. Comments are kept.
The Minify mode does the opposite. It puts the query on one line and removes comments, which is handy for embedding SQL in code or a config file. It never touches text inside quotes, and it keeps optimizer hints and MySQL executable comments, because removing those would change what the query does. Everything is done in your browser, your SQL is not sent anywhere, and the query is never run.
How to use
- Paste your SQL into the input box, or press Load sample.
- Choose your database in the Dialect box. If you see a parse error, check this first.
- Pick the indent and the keyword case, and adjust the layout options if you want a different style.
- Read the formatted SQL in the output box. It updates as you type.
- Press Copy result or Download .sql. Switch to Minify to get a single line instead.
Example
Input
select id,name from users where active=1 and age>30 order by name
Output
SELECT id, name FROM users WHERE active = 1 AND age > 30 ORDER BY name (each clause on its own line, indented)
What formatting changes
The same query before and after, and which setting controls each change.
| Syntax | Meaning |
|---|---|
select → SELECT | Keyword case (uppercase, lowercase or keep as typed) |
a,b → a, b on separate lines | Each column or item gets its own line |
a=1 → a = 1 | Spaces around operators (turn off with “No spaces around operators”) |
WHERE x AND y | AND and OR start the line, or end it, as you choose |
IN (1, 2, 3) | Short bracketed lists stay on one line, longer ones are split |
query; query; | Blank lines between queries, from none to two |
-- note | Comments are kept in place |
Frequently asked questions
- Why do I get a parse error?
- The formatter has to understand the query to lay it out. The most common cause is the wrong dialect: a PostgreSQL query using $$ quoting or ::, or a SQL Server query with [square brackets], will not read as standard SQL. Choose your database in the Dialect box. Unclosed quotes and brackets also cause errors.
- Does formatting change what my query does?
- No. Only whitespace and the letter case of keywords change, and strings, names and comments are left as they are. Check the keyword case setting if you want it kept exactly as typed.
- Does it check that my SQL is correct?
- No. It reads the query only well enough to format it, so a query can be laid out neatly and still be wrong for your database, for example with a table that does not exist. It is never run, and nothing is sent to a server.
- What does Minify remove?
- Comments and extra whitespace, so the query fits on one line. Text inside quotes is never changed. Optimizer hints such as /*+ INDEX(t i) */ and MySQL executable comments such as /*! ... */ are kept, because the database acts on them.
- Is there a limit on the size of the query?
- Inputs up to 2 million characters are formatted, and long scripts are processed in the background so the page stays responsive. Formatting takes roughly a second for every 250,000 characters.
Related tools
- Fake Data GeneratorMake test data from fields you choose or a JSON Schema, as JSON, CSV or SQL INSERT, repeatable with a seed.
- CSV to JSON & JSON to CSVConvert CSV to JSON and JSON to CSV with delimiter detection and nested JSON flattening.
- JSON Formatter & ValidatorFormat, minify and validate JSON online with line-accurate error messages.
- Text Diff CheckerCompare two texts online and see added and removed lines side by side.
- Regex TesterTest regular expressions online with live match highlighting and groups.