# SQL Query Formatter & Minifier

Beautify or minify SQL with full control over dialect (PostgreSQL, MySQL, SQLite, SQL Server/T-SQL, BigQuery, Snowflake, and more), keyword / identifier / function casing, indent style (standard, tabular-left, tabular-right), and spacing between statements. Produces a syntax-highlighted, copy-ready result with live size and statement stats.

> Canonical page: https://elysiatools.com/en/tools/sql-query-formatter

- **Category:** Development

- **Keywords:** sql formatter, sql beautifier, sql minifier, format sql, prettify sql, sql indentation, postgresql, mysql, sqlite, tsql, bigquery, snowflake, sql keywords uppercase, query formatter, database

## Overview

A SQL beautifier and minifier for backend developers, BI analysts, DBAs and SQL learners:

1. **Mode** — choose *Format (beautify)* for readable multi-line output, or *Minify (one line)* to collapse a query into a single compact line.
2. **Dialect** — pick the SQL flavor (Standard SQL, PostgreSQL, MySQL, SQLite, T-SQL, BigQuery, Snowflake, …) so keywords and functions parse correctly.
3. **Casing** — independently set the case of keywords, identifiers, and function names (Preserve / UPPER / lower).
4. **Indent** — standard, tabular-left or tabular-right alignment, with configurable indent width and blank lines between statements.
5. **Output** — a dark, syntax-highlighted, copy-ready code block plus a stat strip (input/output bytes, line count, statement count, dialect).

Powered by the battle-tested sql-formatter library — handles complex JOINs, subqueries, CTEs and window functions.

## Inputs

- **SQL input** (textarea): SELECT * FROM users WHERE active = 1 ORDER BY name;
- **Mode** (select)
- **SQL dialect** (select)
- **Keyword case** (select)
- **Identifier case** (select)
- **Function case** (select)
- **Indent style** (select)
- **Indent width** (number): 2
- **Lines between statements** (number): 1
- **Newline before semicolon** (checkbox)

## When to use

- When reviewing complex, unformatted SQL queries containing nested joins, subqueries, or common table expressions (CTEs).
- When preparing SQL queries to be embedded as single-line strings inside application source code or configuration files.
- When standardizing database scripts across a team by enforcing uniform keyword casing and indentation rules.

## How it works

- Paste your raw SQL query into the input area and select your target SQL dialect, such as PostgreSQL, MySQL, or Snowflake.
- Choose between formatting to beautify the layout or minifying to collapse the query into a single line.
- Customize casing rules for keywords, identifiers, and functions, and adjust formatting options like indentation width and statement spacing.
- Copy the syntax-highlighted, formatted SQL output along with real-time statistics on statement count and size changes.

## Use cases

- Beautifying nested subqueries and window functions for easier debugging and code reviews.
- Compacting database migration scripts into single-line strings for deployment pipelines.
- Standardizing legacy SQL scripts to use uppercase keywords and consistent 2-space indentation.

## Frequently asked questions

### Which SQL dialects does this formatter support?

It supports Standard SQL, PostgreSQL, MySQL, SQLite, SQL Server (T-SQL), BigQuery, Snowflake, MariaDB, PL/SQL, Redshift, Spark, Hive, DB2, and DuckDB.

### Can I convert all SQL keywords to uppercase automatically?

Yes, you can set the keyword casing option to UPPER, lower, or preserve the original casing.

### What is the difference between standard and tabular indentation styles?

Standard style uses traditional nested spacing, while tabular styles align keywords to the left or right of a vertical column for structured readability.

### Does minifying SQL remove comments and extra whitespace?

Yes, minification collapses the query into a single line and strips unnecessary spaces to optimize the query size.

### Can this tool format multiple SQL statements at once?

Yes, it formats multiple statements and allows you to configure the number of blank lines between them.

## Related tools

- [SQL Formatter](https://elysiatools.com/en/tools/sql-formatter): Format SQL queries
- [CSS Beautifier](https://elysiatools.com/en/tools/css-beautifier): Format and beautify minified or messy CSS code into readable, well-indented stylesheets
- [JavaScript Deobfuscator](https://elysiatools.com/en/tools/javascript-deobfuscator): Deobfuscate and analyze obfuscated JavaScript code to improve readability and understanding
- [Batch Image Compress](https://elysiatools.com/en/tools/batch-compress): Compress multiple images with quality control, output format selection, and size optimization
- [Convert TIFF to Compressed TIFF](https://elysiatools.com/en/tools/tiff-to-compressed-tiff): Convert TIFF images to compressed TIFF format with various compression methods and optimization settings
- [Convert TIFF to JPEG](https://elysiatools.com/en/tools/tiff-to-jpg): Convert TIFF images to JPEG format with quality control and background color options
- [Convert TIFF to PDF](https://elysiatools.com/en/tools/tiff-to-pdf): Convert TIFF images to PDF format with customizable page size, orientation, and compression settings
- [Convert TIFF to WebP](https://elysiatools.com/en/tools/tiff-to-webp): Convert TIFF images to WebP format with quality control and transparency support

## Samples

- [SQL Scripts Samples](https://elysiatools.com/en/samples/sql-samples): SQL query examples and database scripts for various scenarios and use cases (primarily MySQL syntax)
- [SQL Viewer Samples](https://elysiatools.com/en/samples/sql-viewer-samples): Sample SQL scripts (DDL/DML, joins, CTEs) for the in-browser SQL Viewer
- [SQL Injection Samples](https://elysiatools.com/en/samples/sql-injections): Educational collection of SQL injection payloads for security testing, vulnerability assessment, and defensive coding practices
- [Drizzle ORM Samples](https://elysiatools.com/en/samples/drizzle): Drizzle ORM lightweight TypeScript ORM examples including schema definition, queries, migrations, relationships, and database patterns

## Related content

- [SQL Query Review, Performance, and Relational Integrity Tools](https://elysiatools.com/en/hubs/sql-query-review-performance-and-integrity): Review SQL before it reaches production: format queries, assemble joins, inspect EXPLAIN plans, catch injection patterns, validate foreign keys, and compare schema drift in one focused hub.
- [Code and Markup Minify, Beautify, and Format Tools](https://elysiatools.com/en/hubs/code-minify-beautify-format-tools): Minify and beautify CSS, HTML, JavaScript, JSON, SQL, XML, YAML, TOML, SVG, and VBA, lint Markdown and email HTML, and format code across languages in one hub for production and review workflows.
- [Database Schema, Migration, and SQL Workflow Tools](https://elysiatools.com/en/hubs/database-schema-migration): Plan table schemas, generate SQL, compare database changes, validate relationships, and move spreadsheet data into database-ready formats in one hub.
- [Text Redaction, Highlighting, and Presentation Formatting Tools](https://elysiatools.com/en/hubs/text-format): Compare tools for masking sensitive text, finding PII, normalizing phone numbers, highlighting phrases, centering text, and formatting diffs in one hub.
