Skip to content
Toolew.com

SQL Formatter

Pretty-print SQL for 20 dialects with configurable keyword case, indentation, operator placement and line width.

Runs in your browser. Your data is not uploaded.
Loading tool…

Tool guide

What this tool does

SQL Formatter reformats SQL queries into clean, consistently indented statements for 20 dialects including PostgreSQL, MySQL, BigQuery, Snowflake and T-SQL. Choose how keywords, functions and data types are cased, pick a standard or tabular layout, control where AND and OR break, and set the maximum width of nested expressions, all powered by the sql-formatter library running in your browser.

A query written on one long line, or copied out of an application log with inconsistent spacing, is hard to review and easy to misread. Formatting SQL the same way every time, one clause per line, aligned joins, consistent keyword case, makes it obvious at a glance what a query selects, joins and filters, and it makes diffs in version control meaningful instead of noisy.

This tool wraps the sql-formatter library, which parses the SQL for the dialect you select rather than applying regular expressions, so dialect-specific syntax such as BigQuery backtick-quoted table names or T-SQL square-bracket identifiers is handled correctly. Keyword, function and data-type case, indent width, line layout, whether AND and OR start a new line, and the maximum width of parenthesised expressions before they wrap are all adjustable, and formatting runs entirely on your device.

How to use SQL Formatter

  1. Paste a query or script, or load the Sample to see the formatter in action.
  2. Pick the matching SQL dialect, such as PostgreSQL, MySQL or BigQuery, from the dropdown.
  3. Set Keywords, Function names and Data types to uppercase, lowercase or kept as written.
  4. Choose an indentation width and a Layout: standard, or tabular with keywords aligned left or right.
  5. Decide whether AND and OR start a new line or end the previous one, and set the max width for nested expressions.
  6. Review the formatted result, then copy it or download it as query.sql.

Tips for better results

  • Selecting the wrong dialect is the most common source of a formatting mistake; BigQuery, Snowflake and T-SQL each quote identifiers differently.
  • Tabular layout with right-aligned keywords lines up SELECT, FROM, WHERE and JOIN for queries with many columns, which some teams find easier to scan.
  • A smaller expression width forces long CASE statements and subqueries to wrap sooner, which can make deeply nested logic easier to follow.
  • Formatting does not change a query’s behaviour, only its layout, so it is safe to run on production SQL before a code review.

Common use cases

  • Cleaning up a query pasted from a slow-query log or a database GUI’s history panel before sharing it.
  • Standardising SQL style across a team before it goes into a shared repository or migration file.
  • Making a large generated query, such as one built by an ORM, readable enough to debug.
  • Preparing SQL snippets for documentation or a blog post with consistent indentation.

Common mistakes to avoid

  • Formatting PostgreSQL-specific syntax such as dollar-quoted function bodies with the generic Standard SQL dialect, which can misread the quoting.
  • Assuming uppercase keywords are required; it is purely a style choice, and most databases are case-insensitive for keywords.
  • Expecting the formatter to fix a syntax error; it needs valid SQL for the chosen dialect to parse successfully.

Frequently asked questions

Which SQL dialects are supported?

Twenty, including standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, T-SQL, PL/SQL, BigQuery, Snowflake, Redshift, DuckDB, ClickHouse, Spark SQL, Hive and Trino. Pick the one matching your database for the most accurate result.

Will formatting change what my query does?

No. Only whitespace, line breaks and the letter case of keywords, functions and data types change. The statement’s logic, literals and identifiers are left exactly as written.

What does the expression width setting control?

It sets the maximum character width a parenthesised expression, such as a CASE statement or a subquery, can reach before the formatter breaks it onto multiple lines instead of keeping it on one.

Can I format multiple statements at once?

Yes. Paste several semicolon-separated statements and each is formatted in place; the blank-lines setting controls how much space is left between them.

Feedback & suggestions

Help us improve SQL Formatter. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.