How to format SQL by database dialect

SQL formatting improves the visual structure of clauses, joins, expressions, and subqueries, but the selected dialect determines how vendor-specific syntax is parsed.

Open the SQL Formatter

What SQL formatting changes

A formatter adjusts whitespace, indentation, line breaks, and keyword case. It can make joins, predicates, grouped expressions, and nested queries easier to review without connecting to a database or running the statement.

A well-formatted query can still be slow, unsafe, or logically wrong. Formatting is a reading aid rather than execution analysis.

How to format SQL

  1. Choose Standard SQL, PostgreSQL, MySQL, SQLite, T-SQL, or BigQuery.
  2. Select two spaces, four spaces, or tabs.
  3. Choose uppercase, lowercase, or preserved keyword case.
  4. Paste the query and select Format SQL.
  5. Review quoted identifiers, placeholders, and vendor-specific statements.

Choosing the dialect first is important because identifier quotes, parameter forms, operators, and statement syntax vary.

A SQL formatting example

Input

select u.name,count(o.id) from users u left join orders o on o.user_id=u.id group by u.name

Readable output

SELECT
  u.name,
  COUNT(o.id)
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY u.name

Why dialect selection matters

AreaPossible differences
IdentifiersDouble quotes, backticks, or brackets
Parameters?, $1, @name, named forms
PaginationLIMIT, TOP, or fetch syntax
Procedural codeVendor-specific blocks and delimiters

What formatting does not check

  • Whether tables and columns exist.
  • Whether permissions allow the statement.
  • Whether user input is parameterized safely.
  • Whether indexes support the query plan.
  • Whether every stored procedure or extension is supported by the formatter.

Use the database's parser, explain plan, tests, and security review for those questions.

Use the browser tool

Format common SQL locally with a selected dialect, indentation style, and keyword case.

Format SQL now