Code converters

SQL Formatter and Beautifier

Turn one-line or messy SQL into clean, consistently indented queries in 12 dialects, or minify it safely, with parse errors pinpointed to the line and column.

  • Free foreverNo trial, no paywall, no usage limits.
  • No sign-upOpen the page and start. We never ask for an email to use a tool.
  • PrivateEverything runs in your browser. Your input is never uploaded or stored on our servers.
  • Works offlineOnce the page has loaded, the tool keeps working without a connection.
Mode
Pretty-print with indentation and one clause per line.Collapse to the smallest safe form for logs, URLs or embedding in code.
Each database quotes identifiers, strings and comments differently. Pick yours so nothing is misread.
KeywordsLetter case for reserved words such as SELECT and JOIN.
SELECT, FROM, WHERE: the classic style that makes keywords stand out.select, from, where: quieter, common in modern codebases.Leave every keyword exactly as you typed it.
IndentSpaces per level, or a tab so each reader picks their own width.
Two spaces: compact, the most common choice.Four spaces: easier to scan in deeply nested queries.One tab per level.

Your SQL

Paste a query, a migration or a whole .sql file. Drop a file onto the editor to open it.
Clear

Formatted SQL

Use result as inputCopyDownload query.sql
Paste SQL to format it as you type. Everything runs in your browser.

Need this built into your own API or pipeline? Talk to our team

Quick answer

A SQL formatter rewrites the whitespace and letter case of a query so its structure is obvious: one clause per line, indented subqueries and CTEs, consistent keyword case. Unless you change identifier case, it never changes what the query does. Paste SQL into Playxoft's free SQL Formatter, pick your database dialect, then choose keyword case and indent: the result updates as you type, Minify compresses it instead, and errors show the exact line and column.

  • 12 SQL dialects
  • Keyword and identifier case
  • 2, 4 or tab indent
  • Safe minify
  • Line:column errors
  • Open and download .sql files

How to use the SQL Formatter

  1. 1Paste your SQL, drop a .sql file onto the editor, or click Load example.
  2. 2Pick your database under Dialect so strings, quoted identifiers and comments are read correctly.
  3. 3Choose Keywords case and Indent. Open More options for identifier case, tabular alignment and where logical operators break.
  4. 4Switch Mode to Minify to collapse the query onto one line, with Strip comments if you want it smaller still.
  5. 5Copy the result, download it as query.sql, or press Ctrl + Enter in the editor to copy without reaching for the mouse.

What does a SQL formatter do?

A SQL formatter reads your query as a stream of tokens (keywords, identifiers, strings, operators, comments) and prints it again with consistent line breaks and indentation. Only whitespace and, if you ask for it, the letter case of keywords change. String literals, quoted identifiers and comments come out exactly as they went in, so the formatted query returns the same rows.

-- Before
select u.id,u.email,count(o.id) orders from users u left join orders o on o.user_id=u.id where u.active group by 1,2

-- After
SELECT
  u.id,
  u.email,
  count(o.id) orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.active
GROUP BY
  1,
  2

Formatting is also a cheap syntax check: if the formatter cannot parse a statement, you get the line and column of the first token it could not place, which is usually an unclosed quote, a stray parenthesis or the wrong dialect.

Should SQL keywords be uppercase or lowercase?

Both are correct: SQL keywords are case-insensitive in every major database. The choice is about readability and team habit.

  • Uppercase (SELECT, LEFT JOIN) is the traditional style and what the widely shared SQL Style Guide recommends. Keywords stand out from table and column names even in plain text, in logs and in code review tools without syntax highlighting.
  • Lowercase (select, left join) is popular in analytics and application code, where editors already color keywords and capitals feel like shouting.

Pick one and apply it everywhere, which is exactly what a formatter is for. Be more careful with identifier case: PostgreSQL folds unquoted names to lowercase, but MySQL table names can be case-sensitive on Linux, so changing them can break a query. Leave Identifiers on *Keep as written* unless you know your database ignores case.

Leading or trailing commas?

Trailing commas put the comma at the end of each line; leading commas put it at the start of the next:

-- Trailing (this formatter's output)
SELECT
  id,
  email,
  created_at
FROM users

-- Leading
SELECT
    id
  , email
  , created_at
FROM users

Leading commas make it easy to comment out the last column and keep diffs to one line when you append one. Trailing commas read like ordinary prose and are what most formatters and style guides produce, so this tool uses them. Whichever you choose, never leave a comma before FROM: most databases reject it.

How should CTEs and subqueries be formatted?

Treat each common table expression (WITH name AS (…)) like a small named query: the name and AS ( on one line, the body indented one level, the closing parenthesis back at the margin, and a comma before the next CTE. The final SELECT starts at the left margin so the reader can find the query's output immediately.

WITH
  paid AS (
    SELECT customer_id, sum(total) AS revenue
    FROM orders
    WHERE status = 'paid'
    GROUP BY customer_id
  )
SELECT c.name, p.revenue
FROM customers c
JOIN paid p ON p.customer_id = c.id

Subqueries follow the same rule: indent the inner query one level deeper than the clause that contains it. Short expressions such as IN (1, 2, 3) stay on one line; raise or lower Inline width under More options to control when they break.

How do SQL dialects differ?

The core of SQL is shared, but the details a formatter must understand are not. Choosing the right Dialect stops it from misreading a quote or a comment:

FeaturePostgreSQLMySQL / MariaDBSQL ServerBigQuerySQLite
Quoted identifier"name"backticks[name]backticks"name" or [name]
Limit rowsLIMIT 10LIMIT 10TOP 10 or FETCH NEXTLIMIT 10LIMIT 10
Auto-incrementGENERATED ALWAYS AS IDENTITY (or serial)AUTO_INCREMENTIDENTITY(1,1)noneINTEGER PRIMARY KEY (AUTOINCREMENT optional)
Castx::int or CASTCAST(x AS SIGNED)CAST, CONVERTCAST, SAFE_CASTCAST
Extra comment stylenone# commentnone# commentnone
Function bodies$$ … $$BEGIN … ENDBEGIN … ENDBEGIN … ENDnot supported

Even string concatenation differs: a || b in PostgreSQL, SQLite and BigQuery, CONCAT(a, b) in MySQL (where || means OR unless PIPES_AS_CONCAT is set) and a + b or CONCAT(a, b) in SQL Server (SQL Server 2025 and Azure SQL also accept ||). Standard SQL works for portable queries. If you see an "Unexpected" error on code that runs fine in your database, switching the dialect is the first thing to try.

Is minifying SQL safe?

Yes, when it is done on tokens rather than with a regular expression. The minifier here collapses whitespace only between tokens, so the inside of every string, quoted identifier and dollar-quoted body is untouched. Line comments are kept with their line break (otherwise -- note would swallow the rest of the query), or removed entirely with Strip comments. Optimizer hints such as /*+ INDEX(users) */ and MySQL conditional comments such as /*!50100 … */ are always kept, because they change how the query runs.

Minified SQL is handy for log lines, for embedding a query in a JSON or YAML config, or for comparing two queries that differ only in layout. For anything a person will read, format it instead.

Frequently asked questions

No. Only whitespace and, if you choose it, the letter case of keywords, data types and functions change. Strings, quoted identifiers and comments are kept exactly. The one option to use with care is identifier case, because MySQL table names can be case-sensitive.
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), BigQuery, Snowflake, Amazon Redshift, Oracle PL/SQL, Spark SQL and Trino or Presto. Pick the one your database uses so quoting and comments are read correctly.
Usually the dialect is wrong: backtick or square-bracket identifiers, # comments and $$ function bodies only exist in some databases. Templating placeholders such as {{ ref() }} from dbt or Jinja are not SQL either. Switch the dialect, or replace placeholders with plain names, and format again.
Yes. Statements separated by semicolons are formatted one after another, with blank lines between them that you can set from 0 to 5. Open a .sql file with the Open button or drop it onto the editor.
Format adds line breaks and indentation so people can read the query. Minify removes every unnecessary space and line break, and optionally the comments, so the query fits on one line for logs, configs or code.
No. The formatter runs entirely in your browser, so queries that contain table names, customer data or credentials never leave your machine. Once the page has loaded it also works offline.

Last updated by the Playxoft engineering team.

From the engineers who built this tool

Fighting messy data every day?

When payloads, schemas and integrations keep breaking, the fix is usually upstream. We design typed APIs and backends that stay clean as you grow. Tell us what you are building and we will suggest the simplest architecture that fits.

More free tools

See all tools

cURL to Python Converter

New

Convert cURL commands into Python requests or httpx code with params, json, files and auth.

Open tool

cURL to Fetch Converter

New

Turn any cURL command into JavaScript fetch() code with headers, JSON, forms and auth.

Open tool

cURL to Axios Converter

New

Convert cURL commands into an Axios request config with params, data, auth and timeouts.

Open tool

SQL to Prisma Converter

Turn SQL DDL into a schema.prisma with native types, relations and enums.

Open tool

SQL to Drizzle Converter

Turn SQL DDL into a typed Drizzle schema.ts with indexes, enums and relations().

Open tool

SVG to JSX Converter

Turn SVG markup or files into clean React and React Native components.

Open tool