SQL Formatter
Format SQL queries for PostgreSQL, MySQL, SQL Server, Oracle, BigQuery, Snowflake and more, with keyword case and indentation options, in your browser.
How to format an SQL query
- Paste one or more queries, or click Open a file to load a
.sqlfile (up to 10 MB). - Choose the Dialect of your database, for example PostgreSQL, MySQL or SQL Server (T-SQL).
- Choose how to write Keywords (UPPERCASE, lowercase or Keep as typed) and the Indentation.
- Tick No spaces around operators if you prefer
a=b+1toa = b + 1. - Click Format SQL, then copy or download the result. Changing an option re-formats the query.
The query is only reformatted as text. It is never run and never sent to a database or a server.
What the formatter does
The tool uses the open-source sql-formatter library. It splits each statement into clauses and puts every clause keyword (SELECT, FROM, WHERE, GROUP BY, ORDER BY…) on its own line, with the content of the clause indented below it. Columns in a SELECT list are placed one per line, AND and OR conditions start new lines, and subqueries and CASE expressions are indented by nesting level. Short parenthesised expressions stay on one line. Several statements separated by semicolons are kept apart by a blank line.
Only whitespace and letter case change. String literals, quoted identifiers and comments are kept exactly, so the formatted query returns the same result as the original.
Why the dialect matters
SQL databases share the core language but differ in details, and a formatter has to know them to read the query correctly:
- identifiers are quoted with
"double quotes"in standard SQL and PostgreSQL,`backticks`in MySQL, MariaDB and BigQuery, and[brackets]in SQL Server; - operators such as PostgreSQL’s
->>and::casts, or Snowflake’s:path access, only exist in some dialects; - parameter placeholders differ:
?,$1,:nameor@name; - each dialect has its own reserved words and functions, which the Keywords option changes.
If you get “The query could not be parsed”, first check that the selected dialect matches your database. The error shows the line and column where parsing stopped. Standard SQL is the most restrictive choice; pick your actual database whenever possible.
Keyword case and style tips
Uppercase keywords remain the most common convention because they separate the language from table and column names at a glance. Lowercase is popular in teams that find it easier to read, and Keep as typed leaves your choice untouched. Table, column and function names are never changed: only reserved keywords follow the option. For long files, consistent formatting also makes differences between versions much easier to review.
Frequently asked questions
Which dialects are supported?
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), Google BigQuery, Snowflake, Amazon Redshift, IBM Db2, Db2 for i, Apache Hive, Spark SQL, Trino/Presto, DuckDB, ClickHouse, SingleStoreDB, TiDB and Couchbase N1QL.
Does the tool check that my query is valid?
No. It checks that the query can be read in the chosen dialect, but not that the tables or columns exist or that the query would run. Only your database can confirm that.
Can it format stored procedures?
Partly. Statements inside procedures are formatted, but procedural blocks (BEGIN … END, loops, DECLARE) are laid out more simply than in a dedicated IDE.
Is my query sent to a server?
No. The formatting runs in your browser, so queries containing table names or data stay on your computer.
Why is my comment in a different place?
Comments are kept, but a comment at the end of a line may move with the element it follows when that element goes to a new line.
Related tools
- JSON Formatter and Validator Free JSON formatter and validator that beautifies, minifies and checks JSON in your browser, with syntax errors reported by line and column.
- JavaScript Formatter and Minifier Beautify minified JavaScript, minify it with Terser, or check its syntax with the exact line and column of any error. Runs in your browser only.
- XML Formatter Format, minify and validate XML in your browser. Errors are reported with their line and column. Your files are never uploaded.