SQL Formatter
Paste a SQL query and get clean, readable SQL instantly: one clause per line, consistent indentation and the keyword case you prefer. Pick from 13 dialects — MySQL, PostgreSQL, SQL Server, Oracle, BigQuery and more — or minify a query to one line. Free, and it runs entirely in your browser.
How to format SQL
- Paste your SQL. Paste one or more SQL statements into the input box, or click Sample to try an example query.
- Pick the dialect. Choose the database you write for — Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark, Db2 or Trino — so its syntax is recognized.
- Set your style. Choose uppercase, lowercase or preserved keywords, a 2-space, 4-space or tab indent, the blank lines between queries, and whether AND/OR start or end a line. The output updates as you type.
- Copy or download. Copy the formatted SQL to your clipboard or download it as a .sql file. Switch to Minify to collapse a query onto one line instead.
SQL style conventions this beautifier follows
Most teams converge on the same few rules, and the defaults here match them. Each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — starts its own line, and the columns or conditions under it are indented one level, so you can scan a query top to bottom.
- Uppercase keywords separate SQL syntax from your table and column names. Choose lowercase if your style guide prefers it, or Preserve to leave the case alone.
- Leading AND / OR(“before operator”) lines up every condition at the left edge, which makes it easy to comment one out or review a diff.
- One blank line between statements keeps migration scripts readable; set it to 0 for compact files.
- Spaces over tabs (2 or 4) render the same in every editor, code review tool and query console.
MySQL, PostgreSQL, SQL Server and other dialects
SQL is a standard, but every database extends it. A MySQL formatter has to understand `backtick` identifiers and # comments; a PostgreSQL formatter needs :: casts, $$-quoted function bodies and ILIKE; SQL Server uses [bracketed] names and TOP; Oracle has q'[...]' strings and CONNECT BY; BigQuery uses backticked project.dataset.table paths. Selecting the matching dialect lets the formatter recognize these, so it formats correctly instead of reporting an error. If you are not sure, start with Standard SQL and switch when you see a parse error.
Private by design
Queries often contain table names, customer data or credentials in connection strings. This tool formats everything locally in your browser — nothing is uploaded, logged or stored on a server. Only your chosen options (dialect, case, indent) are remembered in your browser so they are ready next time.
Related tools
Frequently Asked Questions
How do I format SQL online?↓
Paste your query into the SQL Formatter, choose your database dialect, and the formatted SQL appears instantly in the output box. Adjust keyword case and indentation if you like, then click Copy or Download .sql.
Which SQL dialects are supported?↓
Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, Google BigQuery, Snowflake, Amazon Redshift, Spark SQL, IBM Db2 and Trino/Presto. Picking the right one matters because each has its own keywords, quoting and operators.
Is it safe to paste production queries here?↓
Yes. The formatter runs entirely in your browser with JavaScript. Your SQL is never sent to a server, logged or stored; only your formatting preferences are saved in your browser's local storage.
Does formatting change what my SQL does?↓
No. Formatting only changes whitespace, line breaks and, if you choose, the letter case of keywords. Table names, column names and string literals are kept exactly as written. Use Preserve keyword case if you want the text left untouched apart from layout.
Why do I get a parse error?↓
Usually the selected dialect doesn't match your SQL — for example square-bracket identifiers are T-SQL, backticks are MySQL, and $$ blocks are PostgreSQL. Switch to the right dialect, or fix the token at the line and column shown in the error.
How do I minify SQL to a single line?↓
Click Minify above the output. It removes comments and collapses whitespace onto one line while leaving string literals, quoted identifiers and optimizer hints such as /*+ INDEX(...) */ untouched.
Last updated: