Digital ToolPad.

Runs 100% in your browser

Your data never leaves your device. zero uploads.

Free online SQL formatter · 19 dialects · Runs in your browser

SQL Formatter & Beautifier

Paste a query and get clean, indented SQL as you type. Pick MySQL, PostgreSQL, SQL Server, Oracle, BigQuery or 14 other dialects, see syntax errors by line and column, and catch an UPDATE without WHERE before it reaches your database.

How it works
Formatting options

567 B

Formatted SQL

730 B
WITH
  recent_orders AS (
    SELECT
      customer_id,
      COUNT(*) AS orders,
      SUM(total) AS spent
    FROM
      orders
    WHERE
      created_at >= '2026-01-01'
      AND status <> 'cancelled'
    GROUP BY
      customer_id
  )
SELECT
  c.id,
  c.name,
  c.country,
  r.orders,
  r.spent,
  RANK() OVER (
    PARTITION BY
      c.country
    ORDER BY
      r.spent DESC
  ) AS country_rank
FROM
  customers c
  JOIN recent_orders r ON r.customer_id = c.id
WHERE
  c.active = TRUE
  AND (
    c.country = 'US'
    OR c.country = 'CA'
  )
ORDER BY
  r.spent DESC
LIMIT
  20;

UPDATE customers
SET
  tier = 'gold'
WHERE
  id IN (
    SELECT
      customer_id
    FROM
      recent_orders
    WHERE
      spent > 5000
  );

Parsed as Standard SQL (2 statements)Only whitespace and letter case changed. Comments are kept unless you remove them.

Formatted in your browser. Nothing is sent to a server.

Query checks

No issues found

Besides syntax errors, the formatter looks for four mistakes that still run: UPDATE or DELETE without WHERE, = NULL comparisons, and an extra comma before FROM or a closing parenthesis.

Fill placeholders from logs

Turn ?, $1, :name or @name into real values. Paste a JSON array or object (strings are quoted for you), or one value per line.

What is a SQL formatter?

A SQL formatter is a tool that rewrites a SQL query with consistent line breaks, indentation and keyword case without changing what the query does. SQL formatter and SQL beautifier are two names for the same thing; some people also call it a SQL pretty printer.

This one parses your query instead of guessing with search and replace, so it knows that a FROM inside a string is text, that a subquery needs its own indent level and that PostgreSQL's :: is a cast. Each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts on its own line, columns and conditions sit one per line below it, and nested queries are indented one more step.

Everything happens in your browser tab. The query is never sent to a server, which matters when the SQL contains table names, customer data in literals or credentials in a connection script. After the page has loaded, it keeps working with the network switched off.

How to format SQL online

  1. 1

    Paste or open your SQL

    Paste a query into Input SQL, press Open file to load a .sql file, or drop the file on the box. The formatted version appears on the right as you type.

  2. 2

    Pick your database dialect

    Choose the dialect your database uses, such as MySQL, PostgreSQL or SQL Server. If the query does not parse, the status bar lists the dialects that can read it.

  3. 3

    Set the style

    Choose keyword case, indent, layout, comma position and where AND and OR go. Your choices are remembered in this browser for next time.

  4. 4

    Copy or download the result

    Copy the formatted SQL, copy it as a JavaScript, Python, Java, C#, Go or PHP string, or download it as a .sql file. Switch to Minify for a single compact line.

SQL formatting options explained

The defaults follow the most common SQL style: uppercase keywords, a 2-space indent and commas at the end of the line. Every option changes only whitespace and letter case, so you can try them freely and watch the output update.

SQL formatter options and what each one does
OptionChoicesWhat it changes
KeywordsUPPERCASE, lowercase, keep as typedCase of keywords, data types and built-in functions. Table, column and alias names are never changed.
Indent2 spaces, 4 spaces, tabsThe width of each nesting level, for clauses, subqueries and CASE blocks.
LayoutStandard, aligned left, riverStandard puts each clause keyword on its own line. Aligned left keeps the keyword and its first item on one line in a column. River right-aligns the keywords so the clause bodies line up.
CommasEnd of line, start of lineStart of line is the comma-first style: adding or removing a column changes only one line in a diff.
AND / ORStart of line, end of lineWhere logical operators sit when a WHERE or ON condition is split over several lines.
Inline lists up to30, 50, 80 or 120 charactersA list in parentheses, such as IN (1, 2, 3), stays on one line when it fits within this width.
Lines between queries1, 2 or 3Blank lines between statements when you format a whole script.
Remove commentsOn or offDrops -- and /* */ comments. Optimizer hints such as /*+ INDEX(t) */ are kept.
Semicolon on its own lineOn or offMoves the closing ; to a new line, a style some teams use in long scripts.

Supported SQL dialects

The formatter supports 19 dialects. Pick the one your database uses, because each reads quoting, comments and placeholders differently. Standard SQL works for plain ANSI queries but rejects vendor syntax such as backtick names or [bracketed] names.

SQL dialects and the syntax each one understands
DialectSyntax it understands
MySQL, MariaDB, TiDB, SingleStore`backtick` names, # comments, backslash escapes in strings, ? placeholders, LIMIT
PostgreSQL, Redshift:: casts, $$ dollar-quoted strings, E'' strings, $1 placeholders, RETURNING
SQL Server (T-SQL)[bracketed] names, TOP, @variables, @@ROWCOUNT, GO batches
Oracle (PL/SQL):bind variables, BEGIN ... END blocks, CONNECT BY, q'[ ]' strings
SQLite[bracketed] and `backtick` names, ?, :name, @name and $name parameters
BigQuery`project.dataset.table` names, # comments, STRUCT and ARRAY types, QUALIFY
Snowflake$$ strings, col:path JSON access, QUALIFY, FLATTEN
Spark SQL / Databricks, Hive, Trino / PrestoBacktick names, LATERAL VIEW, ARRAY and MAP types
DuckDB, ClickHouse, IBM Db2, Couchbase N1QLEach engine's own functions, types and quoting rules

Query checks: mistakes that still format cleanly

A query can be valid SQL and still do something you did not intend. After formatting, the tool looks for four of these and lists each one with its line number, so you can click straight to it. None of the top-ranking online SQL formatters we reviewed do this.

UPDATE without WHERE
UPDATE customers SET tier = 'gold' changes every row in the table. The check ignores UPDATE STATISTICS and ON UPDATE in table definitions.
DELETE without WHERE
DELETE FROM logs empties the table. If that is the plan, TRUNCATE is usually faster. DELETE TOP (n) and DELETE ... LIMIT n are not flagged.
= NULL in a condition
WHERE email = NULL never matches a row, because comparing with NULL returns unknown. Write IS NULL or IS NOT NULL. SET email = NULL is fine and not flagged.
Extra comma before FROM
SELECT id, name, FROM users fails in most databases. BigQuery, Snowflake and DuckDB allow it, so the check is off for those dialects.

Fill placeholders from ORM and application logs

Logged SQL from an ORM usually has placeholders instead of values, such as WHERE id = ? or WHERE id = $1. Paste the values into Fill placeholders and the formatted query shows the real values, ready to run in your database client.

  • A JSON array fills ? and $1, $2 in order: [42, "active"] becomes 42 and 'active'.
  • A JSON object fills named placeholders: {"id": 42} replaces :id, @id or $id.
  • Rails-style pairs work too: [["id", 42], ["status", "active"]].
  • Plain lines are used exactly as typed, one value per line, or name = value for named placeholders.
  • Strings in JSON are quoted and escaped for you, null becomes NULL and true becomes TRUE. A ? inside a string literal or a comment is left alone.

What a SQL formatter checks, and what it does not

A formatter reads the structure of your query, so it catches broken syntax, but it does not connect to your database. Use this table to decide when you need something more.

What this SQL formatter checks compared with a database
ProblemCaught here?How to catch it otherwise
Unclosed parenthesis or stringYes, with line and columnYour database returns a syntax error
Syntax from the wrong dialectYes, and it suggests the dialects that parseRun it on the target database
UPDATE or DELETE without WHEREYes, as a query checkCode review, or safe-updates mode in MySQL
Misspelled table or column nameNo, it has no schemaRun the query, or prefix it with EXPLAIN
Slow query or missing indexNoEXPLAIN or EXPLAIN ANALYZE in your database
Wrong resultsNoTest with known data

Benefits of this SQL beautifier

Private by design
Formatting runs in a Web Worker in your tab. No query, file or setting is sent to a server, and there is no account or sign-up.
Proof that only layout changed
The status bar compares the output with your input and confirms when only whitespace and letter case differ, so you can replace the original with confidence.
Errors you can find
A syntax error shows the line and column with a Go to error button, and the tool tries every other dialect to tell you which ones can read the query.
Big scripts stay smooth
Files up to 10 MB open directly, and formatting happens off the main thread, so typing does not freeze the page.
Ready for your code
Copy the result as a JavaScript template literal, Python triple-quoted string, Java text block, C# verbatim string, Go raw string or PHP nowdoc, with escaping handled.
Works on any device
It runs in any modern browser on Windows, macOS, Linux, ChromeOS, Android and iOS, with nothing to install.

Common uses for a SQL formatter

  • Reading a long query copied from a log, a monitoring tool or a stack trace that arrived as one line.
  • Reviewing a pull request where the SQL is easier to follow with one column and one condition per line.
  • Debugging ORM output from Hibernate, Entity Framework, Prisma, Sequelize or ActiveRecord, with the placeholders filled in.
  • Pasting a tidy query into a ticket, wiki page or Slack thread.
  • Minifying a query to fit a JSON config, an environment variable or a single log line.
  • Agreeing on one style across a team: uppercase keywords, a fixed indent and comma position.

SQL style tips that make queries easier to read

  • Write keywords in uppercase and names in lowercase, so the structure stands out from the data. Databases ignore keyword case, so this is purely for readers.
  • Put each selected column on its own line. Diffs then show exactly which column was added or removed.
  • Give tables short, meaningful aliases (c for customers, o for orders) and use them on every column once a query joins two or more tables.
  • Prefer explicit JOIN ... ON over listing tables with commas in FROM; the join condition then sits next to the table it belongs to.
  • Use a CTE (WITH name AS (...)) instead of nesting subqueries three levels deep.
  • End every statement with a semicolon, even when your client does not require it, so scripts can be split and run safely.

SQL formatter questions

Is it safe to paste production SQL into this formatter?

Yes. The SQL formatter runs entirely in your browser, in a Web Worker on your own device, and nothing you paste or open is uploaded or stored on a server. Your options are saved only in your browser's local storage. Once the page has loaded you can disconnect from the network and it still works.

Does formatting SQL change what the query does?

No. Formatting changes only whitespace, line breaks and the letter case of keywords, data types and built-in functions. Strings, quoted names, numbers and table and column names stay exactly as you wrote them. The status bar confirms this on every run by comparing the output with your input; if anything else differs, it tells you.

Why does my query show a syntax error when it runs fine in my database?

Usually the selected dialect does not match your database. Standard SQL, for example, rejects MySQL `backticks` and SQL Server [brackets]. When a query fails, the tool tries all 19 dialects and shows buttons for the ones that can parse it, so one click fixes it. If no dialect parses it, the error points to the line and column to check.

What is the difference between a SQL formatter and a SQL beautifier?

There is no real difference. Both terms describe a tool that adds line breaks, indentation and consistent keyword case to make SQL readable. Beautifier is more common for tools that also minify, which this one does: switch to Minify to get the shortest single-line version.

Can I format a whole .sql file with many statements?

Yes. Open a .sql file up to 10 MB or paste a full script, and each statement separated by a semicolon is formatted with 1 to 3 blank lines between them. The status bar shows how many statements were found, and Download saves the result as a new .sql file named after the original.

Should SQL keywords be uppercase or lowercase?

Either works, because SQL keywords are not case-sensitive. Uppercase keywords (SELECT, FROM, WHERE) are the most common convention because they separate the query structure from table and column names. Many newer teams prefer lowercase for less visual noise. Pick one and apply it everywhere; the Keywords option switches between them in one click.

How do I minify SQL?

Press Minify at the top of the tool. The query is rewritten on one line with comments and extra spaces removed, while strings, quoted names and optimizer hints such as /*+ INDEX(t) */ are kept exactly. The output header shows how much smaller the minified version is.

Does the formatter check table and column names?

No. It has no connection to your database, so it cannot know whether a table or column exists. It catches syntax errors and four common logic mistakes, such as an UPDATE without WHERE. To check names, run the query in a test database or prefix it with EXPLAIN.

100% private: your data never leaves your browser

No registration, no tracking of your content, no server uploads. Don't just take our word for it:

  • No server, no uploads

    Your files and text are processed entirely on your device. Nothing is ever sent to us.

  • Works offline

    Once loaded, this tool keeps working with your Wi-Fi turned off. Try it.

  • Verify it yourself

    Open your browser's DevTools → Network tab. You'll see zero requests carrying your data.

Explore more tools

More utilities for your next task.

Browse all tools