SQL Formatter

Format and minify SQL queries instantly. Supports MySQL, PostgreSQL, SQLite, T-SQL and more.

7 dialectsFormat & minifyNo data stored
Examples:

What is a SQL Formatter?

A SQL formatter (or SQL beautifier) takes raw or minified SQL queries and reformats them with consistent indentation, keyword capitalisation, and line breaks, making complex queries dramatically easier to read and review. Unformatted SQL — especially auto-generated ORM queries or legacy stored procedures — can be nearly unreadable as a single line. A good formatter also validates basic syntax, helping catch structural errors before executing the query against a database.

Common Use Cases

  • Beautify ORM-generated queries for debugging and performance analysis
  • Standardise SQL style across a team's codebase and migrations
  • Review stored procedures or views that were written without formatting
  • Prepare SQL snippets for documentation, bug reports, or code reviews
  • Detect syntax errors in complex multi-join queries before running them

How It Works

This formatter uses the sql-formatter library to parse your SQL into an abstract syntax tree and then serialise it back to text with configurable indentation and keyword case. You can choose the SQL dialect (MySQL, PostgreSQL, SQLite, etc.) to get dialect-specific keyword handling. All formatting runs in your browser — your queries are never sent to a server.

Frequently Asked Questions

Does formatting change how a query executes?

No. SQL is case-insensitive for keywords and whitespace-insensitive. Formatting only affects how the query looks — the database query planner sees the exact same logical structure regardless of indentation.

Why do I need to select a SQL dialect?

Different databases have different reserved words and syntax extensions. Selecting the correct dialect ensures that database-specific keywords (like PostgreSQL's RETURNING or MySQL's LIMIT placement) are handled correctly.

Should SQL keywords be uppercase or lowercase?

Convention favours uppercase keywords (SELECT, FROM, WHERE) to visually distinguish them from table and column names. Most style guides and linters enforce this, though it is purely aesthetic.

Powered by sql-formatter: Formatting uses the open-source sql-formatter library with dialect-aware rules for MySQL, PostgreSQL, SQLite, T-SQL, PL/SQL, and BigQuery.

All formatting runs locally in your browser. No SQL is sent to any server.