SQL Formatter

Paste a query into the box. The formatter starts each clause on its own line and changes only spacing and keyword case, so strings, comments and identifiers keep their text. Pick the dialect that matches your database, because quoting and comment rules differ.

SQL Formatter runs entirely in your browser: the text you paste is never sent to a server. It is free and needs no sign-up.

How to use it

  1. Paste your SQL Paste a statement or a script into the SQL input, up to 1,000,000 characters. Choose the dialect that matches your database, such as MySQL or PostgreSQL.
  2. Choose the layout Pick keyword case (UPPERCASE, lowercase or Keep as written), an indent of 2 spaces, 4 spaces or a tab, and Format for several lines or Minify for one line.
  3. Copy or download Read the result below, then press Copy or Download .sql. If a string, block comment or quoted name is not closed, the tool keeps your original text and shows the line and column.

Questions

Does this tool check whether my SQL is valid?

No. It only changes spacing and keyword case. It does not check syntax, connect to a database or run the query, so a typo is formatted exactly as typed. Strings, comments and identifiers are never changed.

What does the dialect setting change?

It only changes how the text is split into tokens. MySQL reads backtick names and # comments, PostgreSQL reads $ strings and :: casts, SQLite reads square-bracket and backtick names, and SQL Server also reads N'' strings, @variables and #temporary names.

Why does the output show a warning or my original text?

A warning appears when parentheses do not pair up. Your original text is kept when a string, block comment or quoted name is not closed, or when the input is longer than 1,000,000 characters. Fix the spot shown by the line and column, then try again.