SQL-Formatter & Minifier – Complete Documentation, Best Practices & Integrations

Avatar
Manuel Schulz · 18.10.2025 · Development · 20–25 min

The Zerlo SQL-Formatter & Minifier makes SQL immediately readable (Beautify) or compact (Minify). You control Indent (2/4/8 Spaces), Keyword-Case (UPPER/lower/Preserve) and in the Advanced section Comment-Strip as well as Enforce semicolon. Via Quick Access there are sample snippets ready, and with Self-Test you test the behavior in seconds. The page is accessible here: zerlo.net/formattersql.

Content

  1. Quick Start
  2. Functions at a glance
  3. Quick-access examples (Use cases)
  4. Advanced Options (Details & Pitfalls)
  5. Typical application categories (12 scenarios)
  6. Integration: Website, iFrame, Teams
  7. Optional JSON API (with examples)
  8. Self-Test (Step by Step)
  9. Pro tips, Performance & Security
  10. Dialect hints & limitations
  11. Troubleshooting & FAQ
  12. Try it now

1) Quick Start

  1. Open zerlo.net/formattersql.
  2. Paste your SQL on the left or type it.
  3. Select the Mode: Beautify (readable) or Minify (compact).
  4. Set Indent (2/4/8) and Keyword-Case (UPPER/lower/Preserve) on..
  5. Optional: Remove comments, Enforce semicolon.
  6. Click Format – – the result appears on the right, including Copy and Save as .sql.
  7. Under Self-Test you can automatically test the core rules..

2) Features at a glance

3) Quick Access Examples (Use-Cases)

These examples cover the most common patterns and are ideal as a starting point.

1_einfaches_select.sql
SELECT id, name FROM products WHERE status = 'active';
2_join_mit_aggregat.sql
SELECT c.id, c.title, COUNT(p.id) AS products
FROM categories c
LEFT JOIN products p ON p.category_id = c.id
GROUP BY c.id, c.title
ORDER BY products DESC;
3_case_plus_subquery.sql
SELECT u.id, u.email,
  CASE
WHEN o.total >= 1000 THEN 'gold'
WHEN o.total >= 200  THEN 'silver'
ELSE 'bronze'
  END AS tier
FROM users u
LEFT JOIN LATERAL (
  SELECT SUM(total) AS total
  FROM orders
  WHERE user_id = u.id
) o ON TRUE;
4_cte_plus_window.sql
WITH ranked AS (
  SELECT id, customer_id, total,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY total DESC) AS rn
  FROM orders
)
SELECT * FROM ranked WHERE rn = 1;
5_insert_returning.sql
INSERT INTO users(email, role)
VALUES ('[email protected]', 'editor')
RETURNING id, email;
6_update_mit_case.sql
UPDATE accounts
SET status = CASE
  WHEN balance < 0 THEN 'overdue'
  WHEN balance = 0 THEN 'zero'
  ELSE 'ok'
END
WHERE active = 1;
7_delete_plus_exists.sql
DELETE FROM sessions s
WHERE EXISTS (
  SELECT 1 FROM users u
  WHERE u.id = s.user_id AND u.deleted_at IS NOT NULL
);

4) Advanced Options (Details & Pitfalls)

5) Typical application categories (12 scenarios)

  1. Code Reviews:: Consistent layout speeds up reviews and prevents style discussions.
  2. Debugging:: Complex JOIN/CASE become immediately visually readable.
  3. Knowledge sharing:: Readable SQL for Wiki/Confluence/README.
  4. Migrations & Scripts:: Semicolon safety, unambiguous blocks.
  5. API Embedding:: Minify + Comment-Strip to embed SQL in apps/services.
  6. BI/Reporting:: Clean queries from BI tools before sharing.
  7. Learning & Training:: CTEs/Window functions shown in a structured way.
  8. Refactoring:: First beautify, then isolate/optimize sections.
  9. Bug reproduction:: Clearly structured queries for support tickets.
  10. Style-guide enforcement:: Team standard (Indent/Case) consistently applied.
  11. Templates:: „Quick Access“ as the basis for new queries.
  12. Release readiness:: Minify for stable, portable artifacts..

6) Integration into Website/Teams

A) Use directly

Here’s the tool: zerlo.net/formattersql

B) iFrame embedding (Intranet/Backoffice)

embed_iframe.html
<iframe src="https://zerlo.net/formattersql" title="SQL Formatter" width="100%" height="900" style="border:0; border-radius:12px;"></iframe>

C) Team Style Guide (Base)

7) Optional JSON API

You can automate formatting in tools/CI/CD. A concise example:

api_request.http
POST https://zerlo.net/formattersql?api=1
Content-Type: application/json

{
  "sql": "select id,name from users where id=1",
  "mode": "beautify",
  "options": { "indent": 4, "keywordCase": "upper", "stripComments": false, "ensureSemicolon": true }
}
api_response.json
{
  "ok": true,
  "result": "SELECT id, name\nFROM users\nWHERE id = 1;",
  "stats": { "ms": 4, "inLen": 43, "outLen": 47 }
}
api_node.js
// Node.js (fetch)
const res = await fetch("https://zerlo.net/formattersql?api=1", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
sql: "SELECT * FROM orders WHERE created_at >= NOW() - INTERVAL '7 days';",
mode: "beautify",
options: { indent: 2, keywordCase: "upper", stripComments: true, ensureSemicolon: true }
  })
});
const data = await res.json();
console.log(data.result);
api_php.php
<?php
// PHP
$payload = [
  "sql" => "SELECT COUNT(*) FROM products;",
  "mode" => "minify",
  "options" => [ "indent" => 2, "keywordCase" => "preserve", "stripComments" => true, "ensureSemicolon" => true ]
];
$ch = curl_init("https://zerlo.net/formattersql?api=1");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode($payload),
  CURLOPT_RETURNTRANSFER => true
]);
$resp = curl_exec($ch);
curl_close($ch);
echo $resp;

8) Self-Test (Step by Step)

  1. Click in the tool below on Self-Test – – three core cases are automatically tested..
  2. Beautify Case:: Keywords UPPER, Keywords UPPER, clear breaks, clean indent.
  3. Minify Case:: Comments removed (if option active), compact output.
  4. Indent Case:: Visible switch between 2/4/8 spaces..
  5. Result appears in the Self-Test pane; if there are deviations: check options and possibly switch mode.

9) Pro Tips, Performance & Security

10) Dialect Hints & Limits

11) Troubleshooting & FAQ

„Nothing changes?“ – Check mode & options; input must not be empty.

„Double semicolons?“ – Enforce option + existing ;: disable the option.

„Comments were not removed“ – Enable comment-strip or switch mode to 'Minify'.

„Very long queries lag in the browser“ – Format large blocks sequentially or use the API.

„Keywords in strings changed?“ – Should not happen; check whether they were real strings (quotes, not backticks).

12) Now Try It

Start here: zerlo.net/formattersql

Did the guide help you? Feel free to share it: