9314JIUsi
Developer tools · pure text processing, no database

SQL Typesetting Shop: Untangle a Twisted Query

A SQL scraped out of a log arrives as one crushed line, and five JOINs in tell you nothing about who connects to whom. Paste it here for one-click indentation: every JOIN of a multi-table query gets its own line, subqueries shift right as a block, CASE WHEN branches align, UNION sections split with blank lines - keyword uppercase optional, and not one character inside quoted strings gets touched.

Manuscript trayAny SQL
Typeset proofFormatted result

Indent
Comma style

SQL you paste is rearranged in this page's memory only - no database connection, no execution, no uploads, works offline. Interface options like indent and comma style live in this device's browser and are lost when you switch devices or clear site data. To remove them, use "Clear my data" in the footer.

How to use it

  1. Paste SQL into the left tray (multiple statements are fine - each gets typeset), or hit a sample button to preview the effect.
  2. Switch indent 2/4, trailing/leading commas and keyword uppercase as needed, then hit "Format".
  3. To verify the layout is stable, hit "Reformat (idempotence check)" - it typesets the proof again and demands a character-for-character match before reporting green.
  4. Copy the result or download it as .sql; to push it back into a log search, hit "Minify to one line".

Typesetting rules

SELECT columns one per line, clauses on their own lines: FROM / WHERE / GROUP BY / ORDER BY / LIMIT each start a line; AND/OR conditions inside WHERE break one per line. In multi-table queries every JOIN gets its own line with the ON condition following.

Subqueries indent as a whole: the subquery inside WHERE id IN (SELECT ...) wraps and shifts right one level; each WHEN/THEN of a CASE WHEN takes its own line, END closes. UNION / UNION ALL sections separate with a blank line.

String literals are never split: content inside single quotes, double quotes, backticks or brackets (commas, newlines, keywords included) is kept whole - 'hello, world' is not two columns, and the column name "select" never gets uppercased.

When it earns its keep

The classic case is slow-query triage: the SQL behind an EXPLAIN arrives as one line; paste it in and the tree-shaped indentation shows which table JOINs which and which condition hangs on which field at a glance. Formatting your SQL before code review is also basic team courtesy.

The reverse direction helps too: compress a typeset query back to one line for log-system searches - two buttons, done.

InputAny SQL text (SELECT/INSERT/UPDATE/DELETE/CREATE TABLE/ALTER/DROP; multiple statements separated by semicolons); ≤1MB
OutputFormatted (indent 2/4; JOIN/subquery/CASE WHEN/UNION on their own lines) or minified (one line); keyword uppercase optional
Key parametersIndent 2 by default; comma style trailing by default; uppercase off by default; ?indent=4&comma=leading&upper=1 deep-links
ProcessingBrowser-local pure text processing - no database, no execution, no uploads; interface options in localStorage
Limits1MB per run (tens of thousands of SQL lines in milliseconds)
Known limitsTypesetting only, no syntax validation (use the site's SQL validator for that); stored-procedure bodies and window-function OVER/PARTITION BY kept as-is without special indentation; SQL inside comments is not parsed

FAQ

Does formatting change the semantics of my SQL?

No. The tool only adjusts whitespace and line breaks - it never adds, removes or modifies a single meaningful character: string literals (content inside single or double quotes, backticks) are preserved verbatim, comma style only moves whitespace and newlines around the comma, and keyword casing does not change SQL semantics (SQL keywords are case-insensitive). Formatting formatted output again yields identical results.

Is content inside quotes touched? What about a column named select?

Never. String literals and quoted identifiers ("select", 'hello, world', `order`) are recognized as single whole tokens - keywords, commas and newlines inside them stay untouched, and keyword uppercasing only applies to real keywords outside quotes. Escaped forms like 'It''s fine' are recognized correctly too.

What is the difference between trailing and leading commas?

Trailing commas (default): the comma stays at the end of the current line, like name, then age on the next. Leading commas: the comma starts the next line, like name then , age - handier when you comment rows out. Rare in SQL but some people swear by it. One click switches between the two styles in the options area.

Which SQL dialects are supported?

The generic SQL skeleton: SELECT/INSERT/UPDATE/DELETE/CREATE TABLE/ALTER/DROP, the JOIN family (INNER/LEFT/RIGHT/FULL/CROSS), UNION/UNION ALL, CASE WHEN, subqueries and CTEs (WITH). MySQL backticks, PostgreSQL double-quoted identifiers and :: casts, SQLite bracket identifiers are all preserved as literals. Stored procedures and window-function OVER clauses are formatted as-is without special indentation.

Is my SQL uploaded or executed anywhere?

No. This page is a pure text processor - it connects to no database, executes nothing, only rearranges characters, and works offline. Interface options live in this browser's localStorage; Clear my data in the footer removes them.

Can formatting serve as SQL validation?

No, and it does not pretend to. This page typesets only and judges nothing about syntax (an unclosed quote gets an error message, but that is all). To check CREATE TABLE structure, constraints and INSERT column counts, use the site's SQL validator - its errors come with line and column numbers.

Related tools