SQL Formatter

Paste a query and get it back neatly indented, with keywords in the case you like. Pick your database so its special syntax is understood, or switch to Minify to squeeze it onto one line.

Your SQL Ctrl+Enter to format
Result
 

Why format SQL?

Queries copied from logs, ORMs or a colleague's chat message usually arrive as one long line. Formatting puts each clause on its own line, indents joins and subqueries, and lines up conditions, so you can see at a glance what a query selects, how tables are joined and where a filter is missing. It also makes code reviews and diffs of SQL files much easier to read.

How to use it

  1. Paste one query or a whole script. Separate statements with semicolons.
  2. Choose your database under Dialect. This matters for syntax that only some databases have, such as PostgreSQL's :: casts and $$ function bodies, SQL Server's [square brackets] and TOP, or MySQL's backticks.
  3. Pick the keyword case and indentation your team uses. The result updates as you type.
  4. Copy the result, download it as a .sql file, or click Minify for a single-line version.

Formatting styles

When to minify SQL

Minifying removes comments and extra whitespace while leaving string values and quoted names untouched. It's handy for putting a query into a JSON config, a log message or a single-line environment variable. Keep the formatted version in your repository; minified SQL is hard to review.

Your queries stay private

Formatting runs entirely in your browser, so table names, customer data in WHERE clauses and connection details are never sent to our server. Your last query is remembered in this browser only.

Frequently asked questions

Which databases are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Amazon Redshift, Spark SQL, Hive, Trino/Presto, IBM Db2, SingleStore, TiDB and Couchbase N1QL.

Does formatting change what my query does?

No. Only whitespace and, if you choose, the letter case of keywords change. String values, quoted identifiers and comments are kept exactly as written.

Why do I get a parse error?

The formatter needs to understand the syntax, so an unclosed quote or bracket, or syntax from a different database, stops it. Check the dialect first: for example, square-bracket names only work with SQL Server selected.

Can it format stored procedures?

It formats the SQL statements inside them. Procedural blocks in PL/SQL and T-SQL are handled on a best-effort basis; very long procedures with vendor-specific control flow may keep some of their original layout.

Is my SQL sent to your server?

No. The formatter runs in your browser and nothing is uploaded.