SQL Formatter

Format and indent SQL code into a clean, readable structure directly in your browser.

This tool runs entirely in your browser. Your files are never uploaded to a server.

SELECT id,name
FROM users
WHERE active=true
ORDER BY name;

What this formatter does

Scans for a fixed set of SQL keywords — SELECT, FROM, WHERE, the JOIN variants, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, UNION [ALL], INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, AND, and OR — and puts each on its own line, matching them case-insensitively and uppercasing them in the output. AND, OR, SET and VALUES are indented two spaces to sit under their clause.

How to use it

Paste a SQL statement into the editor and the formatted result updates immediately. Copy the result when ready, or use Reset to clear the editor; Reset does not restore the original sample.

Formatting behavior

Text inside single- or double-quoted string literals is left untouched, so a keyword that happens to appear inside a quoted value is never split onto its own line. Everything else is scanned for the recognized keyword list; runs of blank lines collapse and trailing whitespace before a line break is trimmed.

Important parser limitation

This is a keyword-spotting text formatter, not a SQL parser, validator, or dialect-aware pretty-printer. It only recognizes the fixed keyword list above — CTEs (WITH), CASE/WHEN, window functions, subqueries, and dialect-specific syntax (T-SQL, PL/pgSQL, etc.) are not specially formatted and pass through as plain text. It doesn't validate that the SQL is syntactically correct, and it doesn't know about column names or table structure.

Safe review workflow

Because formatting is purely keyword-based, review the output before running it, especially for complex queries with nested subqueries or nonstandard syntax where the line breaks may not match how you'd normally structure the query. Keep the original alongside the formatted version.

Privacy

Processing happens locally in your browser. The pasted SQL is not uploaded by this tool.

Frequently Asked Questions

What does the SQL Formatter do?
Format and indent SQL code into a clean, readable structure directly in your browser.
Does this SQL tool change program behavior?
It only changes layout or removable whitespace. Review minified output before production use when code relies on unusual syntax.
Is my code uploaded?
Processing is local and your code is never uploaded.