Skip to content
UniKit

SQL prettifier

Format SQL online with configurable keyword case, indentation, clause line breaks and comma position, plus keyword sets for Standard, MySQL, PostgreSQL, SQL Server, Oracle and BigQuery.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

SQL

Options

Keyword case
Comma position
Formatted SQL

What this tool does

  • Someone handed you a query written as one long line — format it and see at a glance where SELECT, FROM and WHERE begin.
  • Enforce one house style before committing: upper-case keywords, two-space indents, trailing commas, which makes review diffs much cleaner.
  • While chasing a slow query, expand nested subqueries and JOINs so you can confirm the ON and WHERE conditions are not swapped.
  • Paste a formatted query into documentation or a ticket instead of the original single line.

Example

Input

select a,b from t where id=1 and name like 'x%' order by a desc

Output

SELECT
  a,
  b
FROM t
WHERE id = 1
  AND name LIKE 'x%'
ORDER BY a DESC

The defaults are upper-case keywords, two spaces per indent level, trailing commas and a line break before each major clause. AND gets one extra indent level, which is why it sits under WHERE rather than aligned with it.

Frequently asked questions

Can formatting change what the query does?

No. The tool ships its own tokenizer that splits the input into strings, comments, identifiers, numbers and operators, and only whitespace and keyword casing are touched afterwards. Text inside string literals and comments is left alone, so a double space inside LIKE 'a b' survives.

How does it decide what is a keyword? Will it rewrite my column names?

Only words in the built-in keyword set change case. That set is the standard SQL keywords plus the extensions of the selected dialect (MySQL AUTO_INCREMENT, PostgreSQL RETURNING, BigQuery QUALIFY, …). Column and alias names are not in it and stay untouched; the "Preserve" option leaves every letter as typed.

Leading versus trailing commas — what is the difference?

Trailing produces the familiar SELECT / two spaces / a, / b shape. Leading puts the comma at the start of the continuation line, so adding or removing the last field touches a single line in a diff. Only commas inside clause lists break lines; commas inside function calls such as COUNT(a, b) stay on one line.

It reports an unterminated string or unbalanced parentheses.

That means the SQL itself is incomplete: an unclosed quote, a block comment missing its */, or a bracket without a partner. The tool refuses to guess rather than emit a result you might paste somewhere harmful — format the statement in smaller pieces to find the culprit.

Is my SQL uploaded?

No. Tokenizing and layout run entirely in the browser, with no network requests and no storage of what you pasted.

Keywords:sqlsql 格式化prettifybeautify格式化mysqlpostgresqlsql serveroraclebigquery查询

Related tools