# SQL Formatter

URL: https://tools.otaku-dojo.com/en/sql-formatter
Updated: 2026-10-04

The SQL Formatter breaks a one-line query into clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY…), puts each column on its own line, splits AND / OR conditions, indents subqueries and normalizes keyword case — or minifies the query to one line. Strings and comments are kept as-is, and everything runs in your browser.

## How to use the SQL Formatter

1. Paste SQL on the left, or press "Sample" to load a query with a JOIN.
2. Choose Beautify or Minify, keyword case and indentation.
3. The result appears instantly; the status bar warns about unbalanced parentheses.
4. Press "Copy" or "Download" to save a .sql file.

## Specs & key facts

- **Statements**: SELECT, INSERT, UPDATE, DELETE, WITH, all JOIN types, subqueries, CASE, UNION
- **Layout**: Clauses on new lines, one column per line, AND / OR split, indented subqueries
- **Options**: Beautify / minify, keyword UPPER / lower / keep, 2 or 4 spaces
- **Preserved**: Strings, quoted identifiers and comments
- **Not included**: Full syntax validation or execution
- **Processing**: In your browser (queries are never uploaded)

## Examples: Format a JOIN with conditions

```sql
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 and o.status = 'paid' group by u.id
```

→

```sql
SELECT
  u.id,
  COUNT(o.id) AS orders
FROM
  users u
LEFT JOIN orders o
  ON o.user_id = u.id
WHERE
  u.active = 1
  AND o.status = 'paid'
GROUP BY
  u.id
```

## FAQ

### Does it validate SQL syntax?

Not fully — it warns about unclosed quotes and unbalanced parentheses. Run the query against your database to confirm it is valid.

### Which databases are supported?

Common syntax for MySQL, MariaDB, PostgreSQL, SQLite and SQL Server formats well; vendor-specific syntax is kept as-is.

### Can formatting change my query's results?

No. Only whitespace, line breaks and keyword case change; strings and identifiers stay exactly the same.

### Is it safe to paste production queries?

Yes. Formatting runs entirely in your browser and nothing is sent to a server.
