SQL Formatter
Format, minify, or uppercase SQL queries.
SQL Formatter — What It Does
Paste any SQL query — however messy — and instantly produce a clean, consistently indented, readable version. Options include pretty-print formatting with one clause per line, keyword uppercasing, and minification (all whitespace removed). Works with SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, CTEs, subqueries, and JOINs. Runs entirely in your browser.
SQL Formatting Conventions
Unformatted:
Before and After Example
Formatted:
SQL Formatting Tips
Frequently Asked Questions
- Why should I format my SQL queries?
- Formatted SQL is dramatically easier to read, debug, and review. Each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY) on its own line makes query structure immediately visible. Code reviewers can diff formatted SQL effectively, and you can spot logic errors at a glance.
- What SQL dialects does the formatter support?
- The formatter handles standard ANSI SQL constructs as well as common extensions used by MySQL, PostgreSQL, SQL Server (T-SQL), and SQLite. This includes JOIN types, subqueries, CTEs (WITH clauses), window functions, and dialect-specific functions like ISNULL or COALESCE.
- What is SQL minification and when is it useful?
- SQL minification removes all unnecessary whitespace and newlines, producing a compact single-line query. This is useful when embedding SQL in configuration files, URLs, or code that has line-length limits — or when you want to measure character count. It does not affect query execution.
- Should SQL keywords be uppercase or lowercase?
- SQL keywords (SELECT, WHERE, FROM, JOIN, etc.) are case-insensitive in most databases, but the convention in professional codebases is to write keywords in UPPERCASE and identifiers (table/column names) in lowercase or snake_case. This makes keywords visually distinct from identifiers.
- Does formatting SQL change how it executes?
- No. Whitespace (spaces, tabs, newlines) is ignored by SQL parsers. A single-line query and a multi-line formatted version of the same query produce identical execution plans. Formatting is purely for human readability and has no impact on query performance.