InTab

SQL Formatter

Format SQL for MySQL, PostgreSQL, T-SQL, SQLite and more.

Formatters: Pretty-print, minify, validate and compare. It runs in your browser, so nothing you enter is uploaded.

What it does

The SQL Formatter lays out queries so they are easy to read and review: each clause on its own line, consistent indentation and keyword case of your choice. It knows the syntax of the major databases, so dialect-specific features are formatted correctly.

Supported dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark and DB2.

How to use it

  1. Paste a query into the Query pane or click Load sample.
  2. Choose your Dialect.
  3. Pick keyword case (KEYWORDS upper, keywords lower or Keywords as-is) and the indent.
  4. Click Format, or Minify to put the query on one line. Copy the result.

Example

select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=1 group by u.id,u.name order by orders desc limit 10

Formatted, with upper-case keywords:

SELECT
  u.id,
  u.name,
  count(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active = 1
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC
LIMIT
  10

Good to know

  • Formatting changes only whitespace and keyword case, never the meaning of the query. Function names such as count keep the case you typed.
  • Choosing the right dialect matters for things like TOP (T-SQL), backtick identifiers (MySQL) or :: casts (PostgreSQL).
  • The formatter does not run queries or check that tables exist.

FAQ

Will formatting break my query? No. It only re-lays out the text. If the input has a syntax error, formatting may stop with a message instead.

Can I format several statements at once? Yes. Separate them with semicolons as usual.

More Formatters tools

  • JSON Formatter: Beautify, minify, validate and sort JSON. Handles escaped/stringified JSON.
  • XML Formatter: Beautify, minify and validate XML documents.
  • Diff Finder: Compare two texts or JSON documents line by line or word by word.
  • Text Diff Checker: Paste two versions of a text and see exactly which words changed.
  • JSON Validator: Check JSON is valid and see the exact line, column and a fix hint when it is not.
  • JavaScript Formatter: Beautify minified or messy JavaScript with your choice of indentation.
  • JavaScript Minifier: Minify JavaScript with Terser: compress, shorten names and see the size saved.
  • HTML Formatter: Indent and tidy HTML, or minify it for production.
  • CSS Formatter: Beautify CSS with one rule per block and consistent indentation.
  • CSS Minifier: Minify CSS with CSSO: remove whitespace, merge rules and shorten values.
  • YAML Formatter: Validate and re-indent YAML, keeping comments, with optional key sorting.