How to use the SQL formatter
- Paste one or more SQL statements.
- Choose your database dialect and whether keywords should be upper case, lower case or left as typed.
- 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
nameWhy 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.