SQL formatter
Format SQL: keywords in upper case, one clause per line, indented subqueries and CASE blocks.
A simple formatter for SELECT, INSERT, UPDATE and DELETE, not a full SQL parser: it respects strings and comments, but DDL such as CREATE TABLE only gets keyword casing. Up to 200,000 characters.
How it works
A small tokenizer splits the text into words, numbers, quoted strings, quoted names, comments and punctuation, so anything inside quotes or comments is never changed. Reserved keywords are upper-cased. SELECT, FROM, WHERE, GROUP BY, ORDER BY, joins and similar clauses start a new line; select items, SET assignments and VALUES rows go one per line; AND and OR in a WHERE or ON go on indented lines; subqueries in parentheses and CASE blocks are indented. Limits: it is not a SQL parser and does not know any one dialect's grammar. It targets SELECT, INSERT, UPDATE and DELETE; CREATE TABLE and other DDL only get keyword casing, with parenthesized column lists kept on one line. Block comments do not nest, backslash is not an escape character in strings, and identifiers or function names are never case-changed, so a column that is also a keyword may be upper-cased.
Runs in your browser; nothing is uploaded.
FAQ
Does formatting change what the query does?
It only changes whitespace and the case of keywords. String literals, quoted names and comments are kept exactly. Even so, review the result for anything dialect-specific before running it, since this is a text formatter and not a parser.
Which SQL dialects does it support?
It works on common ANSI-style SQL as used by PostgreSQL, MySQL, SQLite and SQL Server for ordinary queries. It understands single-quoted strings, double-quoted and backtick names, -- and /* */ comments, PostgreSQL dollar-quoted strings and $1 parameters. Dialect extensions such as T-SQL square-bracket names or MySQL # comments are not specially handled.
What happens with an unclosed quote or comment?
The formatter stops and reports the line and column where the string, quoted name or comment started. An unbalanced parenthesis is formatted anyway and flagged in a warning.
Related developer tools
Bookmark this page for next time, or copy its link. Shared links contain no working input.
Link to this tool: https://www.toolpick.dev/free-tools/sql-formatter