SQL Formatter

Lay out SQL clauses on their own lines with optional keyword upper-casing.

  • Runs locally in your browser
  • No upload required

Try it

Paste a SQL statement. It is formatted in your browser and never uploaded.

Formatted SQL
SELECT a, b FROM t WHERE x = 1 ORDER BY a
Lines
4
SELECT a, b
FROM t
WHERE x = 1
ORDER BY a

Supported formats

Input
text, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Laid out 1 line(s) of SQL by clause.

How it works

  • Tokenised the statement, treating quoted strings and identifiers as opaque.
  • Started a new line at each major clause keyword (SELECT, FROM, WHERE, GROUP, ORDER, JOIN, ...).
  • Upper-cased recognised SQL keywords.
  • String literals, quoted identifiers and comments are copied exactly.
  • Output is 4 line(s); formatting it again changes nothing.

Methodology

  1. Tokenise the statement, keeping strings, quoted identifiers and comments opaque.
  2. Start a new output line at each recognised clause keyword.
  3. Optionally upper-case known keywords and normalise inter-token spacing.

Usage

  1. Paste or type a SQL statement.
  2. Choose whether to upper-case keywords.
  3. Run the formatter and copy the laid-out query.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Select with a where clause

jsonSelect to copy
{
  "text": "select a,b from t where x=1 order by a",
  "uppercaseKeywords": true
}

String literal preserved

jsonSelect to copy
{
  "text": "select name from users where name='a b'",
  "uppercaseKeywords": true
}

Insert statement

jsonSelect to copy
{
  "text": "insert into t (a,b) values (1,'x')",
  "uppercaseKeywords": false
}

Limitations

Readable queries

A clause-per-line layout makes a query reviewable and its diff meaningful. The formatter keeps values and identifiers untouched so the query means exactly the same thing.

Frequently asked questions

Does it change my string values?
No. Single/double-quoted strings and quoted identifiers are copied exactly.
Which dialects are supported?
The layout is generic SQL; common SELECT/INSERT/UPDATE/DELETE/JOIN clauses are recognised regardless of vendor-specific extras.
Is my query uploaded?
No. The statement is processed entirely in your browser.

Sources

  1. ISO/IEC 9075-1:2023 — Information technology, Database languages SQL — ISO/IEC
  2. MDN Web Docs — SQL — MDN