SQL formatter (format SQL online)
This SQL formatter turns a messy query into readable code: paste it, copy the result. It writes keywords in uppercase, breaks SELECT lists, conditions and joins onto lines and indents subqueries. String literals and identifiers stay untouched. Your query never leaves the browser.
Source: PostgreSQL-Dokumentation – Lexical Structure (Bezeichner, Zeichenketten, Kommentare, Dollar-Quoting). Updated: .
How it is calculated
An unformatted SQL query on a single line is hard to read, review and compare. The formatter turns it into a clear query without changing its meaning.
How to format SQL
- Paste the query into the box (several statements separated by
;are fine). - Choose Format under “Action”; set keyword case, indentation and comma style.
- Copy the result.
What the formatter does
- Clauses (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT) start on a new line; with several columns these are listed one per line.
- Joins get their own lines, and so do
ANDandORin conditions –BETWEEN … AND …stays together. - Subqueries and CTEs (
WITH … AS (…)) are indented, andCASEgets one line perWHEN. - Nothing changes except whitespace and keyword case: string literals, quoted identifiers, numbers, operators and comments stay as typed.
Uppercase or lowercase?
SQL keywords are case-insensitive (ISO/IEC 9075). Uppercase is a common convention so keywords stand out from table and column names; how unquoted identifiers are treated depends on the database, and the tool does not touch them.
Minify
“Minify” turns the query into one line without superfluous spaces and removes comments (optimizer hints /*+ … */ are kept). Handy for embedding SQL in code or config files.
Limits
- The formatter is dialect-neutral and recognises identifiers in
"…",`…`and[…]as well as PostgreSQL text in$$…$$. Dialect-specific forms (such as procedural code with BEGIN … END) are not given special indentation. - Backslash escaping in MySQL strings (
'it\'s') is not recognised; the standard form is'it''s'. - The formatter does not check that a query is correct and never runs it.
Frequently asked questions
How can I format SQL online?
Paste the query into the box – the formatted result appears immediately and can be copied. Processing happens in your browser; nothing is sent.
Does the formatter change my query?
Only whitespace, line breaks and (if you wish) the case of keywords. String literals, identifiers, numbers and operators are preserved character for character; the tool is checked with test cases for exactly that.
Do SQL keywords have to be uppercase?
No. Keywords are not case-sensitive. Uppercase is only a readability convention – choose “Keep as typed” or “lowercase” if your team does it differently.
How do I format a date or numbers in a SQL query?
That is something else: this tool formats the text of the query, not its results. To format output you use database-specific functions such as TO_CHAR (PostgreSQL, Oracle), DATE_FORMAT (MySQL) or FORMAT (SQL Server).
Which SQL dialects are supported?
The tool is dialect-neutral and copes with common queries from PostgreSQL, MySQL/MariaDB, SQL Server, SQLite and Oracle. Database-specific procedural code is not indented separately.
Are my SQL queries stored or uploaded?
No. The query is processed in the browser only, not stored and not added to the address bar – important when table or column names come from a production system.
Sources and legal basis
- PostgreSQL-Dokumentation – Lexical Structure (Bezeichner, Zeichenketten, Kommentare, Dollar-Quoting)
- MySQL Reference Manual – String Literals
- Microsoft Learn – Database identifiers (SQL Server, begrenzte Bezeichner in [ ] und " ")
- ISO/IEC 9075 – Database languages SQL
As of:
Related tools
- JSON formatter, validator and minifierValidate JSON against RFC 8259 with the exact line, column and a plain-English explanation. Beautify or minify, sort keys, copy. Runs locally in your browser.
- CSV to JSON converter (and JSON to CSV)Convert CSV to JSON or JSON to CSV online: delimiter auto-detected, numbers and booleans typed, quoted fields handled. Runs in your browser, nothing uploaded.
- Regex TesterTest JavaScript regular expressions live: matches highlighted, capture groups in a table, every part of the pattern explained. Free, nothing uploaded.
- Text Compare: Find Differences Between Two TextsCompare two texts online and highlight the differences by line, word or character, with a similarity score. Free, private, runs in your browser.
- XML and CSV validator onlineCheck XML for well-formedness and validate CSV against RFC 4180: errors with line and column, auto-detected delimiter, table preview. Runs locally.
- ASCII table with decimal, hex, octal, binary and Unicode lookupComplete ASCII table (0–127) plus Latin-1 (128–255): decimal, hex, octal, binary, HTML entity, control codes. Look up any Unicode character, UTF-8 included.