About this tool
Format SQL queries with readable line breaks, configurable indentation and keyword case — entirely in your browser.
A SQL formatter rewrites the whitespace in a query so each clause starts on its own line and every list item is indented consistently, without changing a single token. This one tokenizes the statement using SQL:2016 lexical rules — single-quoted literals with '' doubling, double-quoted and backtick identifiers, -- line comments and /* */ blocks — then re-emits it with SELECT, FROM, WHERE, GROUP BY, HAVING and ORDER BY on their own lines and JOIN, AND and OR indented under them. It runs entirely in your browser, so the query is never uploaded.
Open SQL Formatter Online on AltFTool — it loads instantly in your browser.
Paste your query into the "SQL to format" box, which starts on a sample SELECT with JOIN, GROUP BY, HAVING and ORDER BY crammed onto single lines.
Set "Indent width (spaces)" to anything from 1 to 8 and "Keyword case" to UPPERCASE, lowercase or "Leave as typed".
The Formatted panel prints the clause-per-line query with Statements, SELECT clauses, Tokens and the minified length beside it; "Copy SQL" takes the formatted text and "Copy one-line" takes the One-line version.
The tokenizer runs client-side, so production SQL is not sent to a server.
String literals, quoted identifiers and comments are copied through byte-for-byte.
1 to 8 spaces of indent, and keywords in UPPERCASE, lowercase or exactly as typed.
No. The formatter only changes whitespace between tokens and, optionally, the case of reserved words such as SELECT and JOIN. It never touches the contents of a string literal, a quoted identifier or a comment, and it never reorders or removes a token, so the parsed statement is identical.
No. Tokenizing and formatting happen in JavaScript in your own browser tab; there is no network request in the process. That matters because real queries usually contain table names, column names and sometimes literal values from production.
The lexer is dialect-neutral and covers the syntax shared by PostgreSQL, MySQL, SQL Server and SQLite: '' string escaping, double-quoted and backtick identifiers, square-bracket identifiers, the :: cast operator and the -> and ->> JSON operators. Because it is lexical rather than a parser, dialect-specific keywords it does not recognise are simply passed through unchanged.
A leading AND at the start of a line makes the conditions in a WHERE clause countable at a glance. The AND that belongs to BETWEEN is part of a single predicate, not a new condition, so the formatter tracks it and keeps it on the same line as its BETWEEN.