SQL formatter

Paste a SQL query to lay it out so it can be read, with keywords in capitals, SELECT, FROM, WHERE and the other clauses on their own lines, and subqueries indented. This is a basic formatter that works for most dialects.

Indent

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Paste your query. Several statements separated by ; are fine.
  2. Choose the indent and whether to uppercase keywords.
  3. Copy the formatted SQL.

What the layout looks like

  • SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and similar clauses start a new line, with their content indented below.
  • Items separated by commas in a SELECT list, GROUP BY, ORDER BY, SET or VALUES go on separate lines.
  • Each JOIN starts a line; AND and OR in WHERE and HAVING start lines too, except the AND that belongs to BETWEEN.
  • A subquery in parentheses is opened on its own line and indented one level deeper.

Example

select a, b from t where x = 1 and y = 2

becomes

SELECT
  a,
  b
FROM
  t
WHERE
  x = 1
  AND y = 2

Tips

Parentheses that are not subqueries, such as IN (1, 2, 3) or function arguments, stay on one line. If a long expression looks wrong, check for an unclosed quote or comment: everything after it is treated as part of the string.

Frequently asked questions

Which SQL dialects does it support?

It is dialect-agnostic. It does not parse SQL; it recognises common keywords and clauses shared by MySQL, PostgreSQL, SQLite, SQL Server and Oracle and only changes whitespace and keyword case. Vendor-specific syntax is spaced sensibly but not laid out specially.

Are my strings and comments changed?

No. Single-quoted strings, quoted identifiers ("name" or `name`), line comments (--) and block comments (/* */) are copied exactly, including their spaces. Only text outside them is reformatted.

What does uppercase keywords do?

It writes SQL keywords such as select, from, join and and in capitals. Table and column names are never changed. A function name like count is capitalised only when it is followed by a parenthesis, so a column called count stays as it is.

Can the formatting change what the query does?

Only whitespace and keyword case are changed, which SQL ignores. Keep an eye on queries that rely on the exact text of a keyword used as an identifier, since a few clause words such as SET or WINDOW are treated as clauses wherever they appear.

Does it format stored procedures or CREATE TABLE statements?

It handles them without errors, but it only has special layout for queries (SELECT, INSERT, UPDATE, DELETE, WITH and set operators). Procedural blocks and column definitions stay on a line.

More in Developer

All tools in this category: Developer ·Updated November 3, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.