How to use the SQL formatter

  1. Choose your database dialect, so its syntax is understood: [brackets] and @variables in SQL Server, $1 and ::casts in PostgreSQL, `backticks` in MySQL.
  2. Paste one or more SQL statements, or select Load example. The result updates as you type.
  3. Adjust indentation, keyword case and layout, then copy or download the formatted SQL.

What the formatter changes

Only whitespace and, if you choose, the case of keywords and data types (select → SELECT, int → INT). Table, column and function names, strings and comments are kept exactly as written, so formatting never changes what a query does. Our tests check this by comparing every formatted query with the original, ignoring whitespace.

Each clause starts on its own line with its contents indented; conditions are split at AND and OR, and parentheses get their own indented block. Aligned keywords puts clause contents in a column instead, a style common in code reviews.

Formatting is not validation

The formatter reads SQL structure, not your schema, and accepts some invalid SQL. It reports problems it can see, such as an unclosed string or parenthesis, with the line and column, but a query that formats cleanly can still fail on your database. Test queries against your database before relying on them.

Frequently asked questions

Is my SQL uploaded?

No. Formatting runs entirely in your browser; queries are never sent to our servers or logged. You can format SQL that contains real table names or data safely.

Can it format stored procedures?

Partly. The statements inside a procedure are formatted, but procedural blocks such as BEGIN ... END and IF ... ELSE aren't indented, and some procedural statements are split across lines. The formatter is at its best with queries and DML: SELECT, INSERT, UPDATE, DELETE, MERGE and DDL such as CREATE TABLE.

Which formatter does it use?

The open-source sql-formatter library (MIT licence), configured with the options above.