SQL Formatter

Format messy SQL into readable, indented statements — or minify it back into a compact single-line form. Handles strings, comments, identifiers and subqueries correctly. Runs entirely in your browser.

SQL

How it works

About SQL Formatter

SQL written by hand, dumped by ORMs, or pasted out of logs is almost always a single cramped line or an inconsistent jumble of casing and indentation. Formatting it safely is harder than it looks — a naive regex that adds newlines before keywords will happily split string literals that happen to contain those words. This tool tokenizes first, so quoted strings, comments and identifiers are treated as opaque units and never broken apart.

The same token stream powers the minifier, which collapses whitespace while keeping keyword/identifier boundaries distinct, so the minified statement parses identically. Use Format to review and edit your query, then Minify to shrink it for embedding in code, configuration files or logs. Both directions preserve comments, string content and identifier casing exactly as written.