consolelog.tools

SQL Query Formatter

Beautify and reformat SQL with a hand-rolled, dialect-aware pretty-printer. Each clause (SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY) starts on its own line; SELECT lists and predicates break and indent, nested parentheses indent further. Control keyword and identifier casing, indent size, comma placement, and data-type casing, then copy, download, or share a URL that restores your query and settings. Minify back to a single line in one click. Everything runs in your browser - your SQL never leaves the page.

About this ToolHow it works, benefits & use cases

Paste a cramped, single-line query and this formatter reflows it into readable, clause-aware SQL. It is powered by a hand-rolled tokenizer and pretty-printer that runs entirely in your browser - no external library, no upload, no server round-trip. Each top-level clause starts on its own line: SELECT, FROM, JOIN (INNER, LEFT, RIGHT, FULL, CROSS), WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, plus INSERT, UPDATE, SET, and DELETE. SELECT lists and SET assignments break onto indented lines at each comma, AND/OR conditions inside WHERE and JOIN predicates start their own indented line, and nested parentheses indent one level further. You control keyword casing (UPPER, lower, or preserve), identifier casing, indent size (2 spaces, 4 spaces, or a tab), comma placement (trailing or leading), and whether data types are forced to uppercase. Pick a dialect - Standard SQL, PostgreSQL, MySQL, or SQLite - to widen the recognised keyword set. Output is live as you type, a Minify button collapses everything back to a single line, and a stats panel surfaces the referenced tables, selected columns, statement kinds, and size. Copy the result, download it as a .sql file, or share a URL that restores your query and every option.

How to Use

  1. 1Paste your query into the SQL input panel, or click "Load example" to drop in a sample multi-join SELECT.
  2. 2Choose a SQL dialect (Standard, PostgreSQL, MySQL, or SQLite) to match the keyword set you use.
  3. 3Set keyword case, identifier case, indent size, and comma style; toggle "Uppercase data types" for CREATE statements.
  4. 4Read the formatted result live in the output panel - no button to press; it updates as you edit.
  5. 5Click Minify to collapse to one line, then copy, download as formatted.sql, or share the URL with your settings intact.

Key Benefits

  • Clause-aware layout: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY each on their own line
  • Independent control of keyword casing and identifier casing
  • Indent with 2 spaces, 4 spaces, or a tab, and choose trailing or leading commas
  • Optional uppercase data types for clean CREATE TABLE output
  • One-click Minify to collapse a formatted query back to a single line
  • Live stats panel: referenced tables, selected columns, statement kinds, and size
  • Runs fully in-browser with zero dependencies - your SQL never leaves your machine

Common Use Cases

  • Cleaning up a minified or single-line query copied from application logs
  • Standardizing keyword casing and indentation across a team before committing migrations
  • Making a complex multi-JOIN query readable during code review
  • Quickly minifying a formatted query to embed it in a string literal
  • Preparing SQL snippets for documentation, tickets, or a blog post

Live output - copy, download, share, or pipe to another tool

Paste a query on the left to see it formatted.

0 characters

Formatting options

Clause-aware layout

The formatter tokenizes your query and lays out each top-level clause - SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY - on its own line, with list items and AND/OR predicates indented underneath.

Safe and reversible

Only whitespace, line breaks, and casing change - never your logic, table names, or string literals. Run it twice and you get the exact same output, and Minify collapses everything back to one line whenever you need it.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools