Skip to main content

SQL Formatter

Pretty-print and beautify SQL queries — real dialect-aware formatting (MySQL, PostgreSQL, SQLite, SQL Server, BigQuery, Snowflake and more) with configurable indent size and keyword casing. Runs entirely in your browser.

Input

Spaces per indent level (ignored when using tabs)

Output

Formatted SQL
 
Was this helpful?

Guides

Paste a messy or minified SQL query and get back a cleanly indented, consistently cased version — instantly, in your browser. The SQL Formatter understands real SQL grammar (not just regex line-breaking), so it correctly indents nested subqueries, multi-line JOIN/ON conditions, CASE expressions, and comma-separated column lists for every major database dialect.

How to use it

Paste your query into the input box, or click Try an example to load a sample SELECT with a JOIN, WHERE, GROUP BY and ORDER BY. Pick the Dialect that matches your database — MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), BigQuery, Snowflake, Redshift, Oracle PL/SQL, and a dozen others are supported, each with dialect-specific keyword and syntax handling. Adjust Indent Size (1–8 spaces) or switch on Use Tabs Instead of Spaces, and choose whether keywords render as UPPERCASE, lowercase, or stay exactly as you typed them. The formatted query updates automatically as you type or change an option; copy it or download it as a .sql file.

Why the dialect matters

SQL isn't one language — it's a family of closely related ones. LIMIT 10 in MySQL/PostgreSQL becomes TOP 10 in SQL Server; BigQuery has backtick-quoted identifiers and its own function set; PL/SQL has BEGIN…END blocks and := assignment. Picking the right dialect means the formatter tokenizes your query with the correct keyword list and grammar rules instead of guessing, so dialect-specific syntax doesn't get mangled or silently dropped.

What it does

  • Breaks each clause (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, …) onto its own line, with column lists and conditions indented beneath it.
  • Indents nested subqueries and parenthesized expressions relative to their enclosing clause.
  • Normalizes keyword casing across the entire query — including compound keywords like INNER JOIN and GROUP BY.
  • Lets you choose 2-space, 4-space, or any custom indent width up to 8 spaces, or tabs.

What it won't fix

This is a formatter, not a linter — it won't catch a missing table alias, a typo'd column name, or logically incorrect SQL. If a query has a genuine syntax error (an unclosed parenthesis, a stray comma), the formatter will report where parsing broke down rather than guess at what you meant.

Formatting vs. minifying

This tool expands SQL for readability. If you need the opposite — collapsing a query to a single compact line for embedding in application code or a URL — use the companion SQL Minifier tool instead.

Is my query private?

Yes. Formatting runs entirely in your browser using an open-source SQL parser — your query is never uploaded, logged, or stored on a server.

sqlformatterbeautifierpretty printdatabasequeryindent

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.