# 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://test.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://test.elysiatools.com/en/tools/sql-formatter): Format SQL queries
- [CSS Beautifier](https://test.elysiatools.com/en/tools/css-beautifier): Format and beautify minified or messy CSS code into readable, well-indented stylesheets
- [RDB SSTable LevelDB RocksDB Memcached Binary KV-Store Encoding Lineage](https://test.elysiatools.com/en/tools/rdb-sstable-leveldb-rocksdb-memcached-binary-key-value-store-encoding-lineage): Decode binary key-value store artifacts byte by byte: Redis RDB snapshots, LevelDB/RocksDB WAL records and SSTable footers, Memcached binary packets, BoltDB and LMDB page headers — with keyspace hex-diff and TTL expiry matrix.
- [SMT-LIB 2.7 / AIGER / BTOR2 Formal Verification Orchestrator (CDCL + BMC + k-Induction + Craig Interpolation + IC3)](https://test.elysiatools.com/en/tools/smt-smtlib-2-7-cvc5-z3-btor2-aiger-k-induction-cddr-dbg-invariant-synthesis-orchestrator): A complete in-browser formal-verification stack — no cvc5/Z3 binary needed: an SMT-LIB 2.7 script parser for the QF_BV + Bool core with Tseitin bit-blasting of the FixedSizeBitVectors operators (add/sub/mul/udiv/urem, shifts, comparators, concat/extract/extend, ite), an AIGER reader (ASCII aag and binary aig with delta decoding; outputs as bad properties), a BTOR2 reader with word-level bit-blasting, and a hand-written CDCL SAT engine (two-watched literals, VSIDS-style activities, 1-UIP learning, restarts) underneath. On sequential models it runs bounded model checking with counterexample-witness traces, k-induction with unique-state strengthening, McMillan-style Craig interpolation computed from the refutation and independently re-certified by SAT before being trusted, and an IC3/PDR-lite frame loop with predecessor-cube blocking.
- [JavaScript Deobfuscator](https://test.elysiatools.com/en/tools/javascript-deobfuscator): Deobfuscate and analyze obfuscated JavaScript code to improve readability and understanding
- [Batch Image Compress](https://test.elysiatools.com/en/tools/batch-compress): Compress multiple images with quality control, output format selection, and size optimization
- [Game Save Viewer](https://test.elysiatools.com/en/tools/game-save-viewer): Drop any game save file — Minecraft NBT, Unreal Engine GVAS, Palworld containers, JSON/XML/INI/Lua text saves, SQLite profiles — and get the detected format, engine versions, key progress fields and a bounded structural tree.
- [Convert TIFF to Compressed TIFF](https://test.elysiatools.com/en/tools/tiff-to-compressed-tiff): Convert TIFF images to compressed TIFF format with various compression methods and optimization settings

## Samples

- [SQL Scripts Samples](https://test.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://test.elysiatools.com/en/samples/sql-viewer-samples): Sample SQL scripts (DDL/DML, joins, CTEs) for the in-browser SQL Viewer
- [SQL Injection Samples](https://test.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://test.elysiatools.com/en/samples/drizzle): Drizzle ORM lightweight TypeScript ORM examples including schema definition, queries, migrations, relationships, and database patterns

## Related content

- [Code Minify, Beautify, and Format Tools](https://test.elysiatools.com/en/hubs/code-minify-beautify-format-tools): Prepare code and markup for review or delivery with readable formatting, compact output, and preservation checks.
- [SQL Query Review for Performance and Integrity](https://test.elysiatools.com/en/hubs/sql-query-review-performance-and-integrity): Build, format, and review SQL with join logic, performance evidence, explain plans, injection checks, foreign-key validation, and schema drift review.
