Skip to content
Buy me a coffee
Formatters

SQL Formatter & Beautifier

Formats any SQL query with your desired indentation level, even if the statement is invalid. Change the case of keywords and identifiers to upper, lower or keep them as-is.

0 characters · 0 lines
Option 2: Or upload your SQL file
Selects the keyword list, string and identifier quoting rules of your database.
Data type names (INT, VARCHAR…) follow the same rule.
Table and column names. Quoted identifiers are never changed.
Ctrl + Enter

About the SQL formatter

The formatter parses your statements and lays them out in the classic "river" style: each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, JOIN…) starts a new line and its content is indented underneath. Selected columns, conditions and VALUES tuples are placed one per line, sub-queries are indented one level deeper, and every statement is separated from the next by the configured number of blank lines. All processing happens in your browser.

Supported statements

SELECT with joins, sub-queries, UNION, window functions and common table expressions (WITH), INSERT, UPDATE, DELETE, MERGE, CREATE / ALTER / DROP for tables, views and indexes, GRANT, transactions, and the procedural extensions of the selected dialect. A statement that cannot be fully parsed is reported with its line and column so you can fix it.

Dialects

The dialect controls which words are treated as keywords, how strings and identifiers are quoted ("…", `…`, […]), which comment markers are recognized (--, #, /* */) and the parameter placeholders (?, :name, $1, @var). Pick Standard SQL when in doubt; it accepts the common core of all databases.

Options

OptionEffect
Indentation levelSpaces (or a tab) added for every nesting level: clause contents, sub-queries, parenthesized lists.
SQL keywords caseRewrites reserved words and data types in upper or lower case, or leaves them exactly as typed.
Identifiers caseRewrites unquoted table, column and alias names. Quoted identifiers keep their case because databases treat them as case-sensitive.
Blank lines between queriesNumber of empty lines inserted after each ;.
AND / OR placementWhether the logical operator starts the new line (WHERE a = 1
  AND b = 2
) or ends the previous one.

Example

select c.id, c.name, count(o.id) as orders from customers c left join orders o on o.customer_id = c.id where c.country = 'FR' and c.active = 1 group by c.id, c.name having count(o.id) > 3 order by orders desc;

formatted with upper-case keywords and three spaces:

SELECT
   c.id,
   c.name,
   COUNT(o.id) AS orders
FROM
   customers c
   LEFT JOIN orders o ON o.customer_id = c.id
WHERE
   c.country = 'FR'
   AND c.active = 1
GROUP BY
   c.id,
   c.name
HAVING
   COUNT(o.id) > 3
ORDER BY
   orders DESC;

Minify SQL

The Minify SQL button collapses the statement onto a single line: comments (--, /* */ and # for MySQL) are removed, runs of whitespace become a single space, and spaces around commas, parentheses, semicolons and comparison operators are dropped. String literals, quoted identifiers and dollar-quoted PostgreSQL blocks are copied untouched, so the query keeps its exact meaning.