SQL Formatter and Minifier

Paste a query to lay it out with one clause per line, or minify it onto a single line. Pick your database so dialect syntax such as T-SQL brackets or PostgreSQL casts is understood. Quoted strings are never changed.

Output will appear here after formatting

How to use the SQL formatter

  1. Paste one or more SQL statements.
  2. Choose your database dialect and whether keywords should be upper case, lower case or left as typed.
  3. Press Format for one clause per line, or Minify for a single line without comments.

Everything runs in your browser. Nothing you type is sent to our servers. Your last input is remembered in this browser only.

What formatting changes, and what it does not

Formatting uses the open source sql-formatter library, which splits your SQL into proper tokens first. That means text inside quotes is never touched: a string such as 'select, from' stays exactly as written, and so do quoted identifiers. Only whitespace, line breaks and the case of keywords change. Comments are kept.

Minify removes comments and every space that is not needed, again leaving quoted text alone, and keeps a space where removing it would change the meaning, such as between two minus signs.

Neither option checks your query against a database. A query can be formatted perfectly and still refer to a table that does not exist.

select id, name from users where active = 1 order by name becomes
SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name

Why the dialect matters

Databases disagree on syntax. SQL Server quotes names with [square brackets] and uses TOP, MySQL uses `backticks`, PostgreSQL has :: casts and $1 parameters, and Oracle has its own PL/SQL blocks. If formatting fails with an unexpected token, the dialect setting is the first thing to check.

When you would use it

  • Making a long query from a log, ORM or colleague readable before you debug it.
  • Keeping SQL in code reviews and migrations in one consistent style.
  • Minifying a query to fit on one line in a config file or a command.

Frequently asked questions

Will formatting change what my query does?

No. Only whitespace and keyword case change, and text inside quotes is left alone. If you ever see a difference in results, the query was probably relying on something outside the SQL, such as session settings.

Why do I get a parse error?

Usually the dialect does not match your SQL, for example [brackets] with Standard SQL selected. Switch to your database's dialect. Unfinished statements and template placeholders such as {{name}} can also stop the parser.

Can it format stored procedures?

Yes, for dialects that have them, such as T-SQL and PL/SQL. Very long procedures are best formatted in sections.

Does it stop SQL injection?

No. Formatting has nothing to do with security. Prevent SQL injection with parameterised queries or prepared statements in your code.

Related tools and guides

This tool runs in your browser. What you enter is processed on your device and is not sent to our servers.

Building something bigger?

We design and build web and mobile applications and the APIs behind them.