SQL Formatter & Beautifier

Paste a query — or a whole migration — and get readable SQL with one clause per line, aligned joins and consistent keyword case, using the grammar of your database.

Runs in your browser
 
Formatted SQL
 

Your data never leaves your computer. All processing happens 100% locally in your browser.

How to use the SQL Formatter

  1. Paste one or more SQL statements into Input SQL (or open a .sql file).
  2. Select your dialect — this matters for things like backtick identifiers in MySQL, :: casts in PostgreSQL or TOP in SQL Server.
  3. Choose keyword case and indentation. The formatted query updates as you type.
  4. Copy the result or download it as query.sql.

What does a SQL formatter do?

SQL is whitespace-insensitive, so queries generated by ORMs, logged by a database or written in a hurry often end up on one enormous line. A SQL formatter parses the statement and re-prints it with each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — starting a new line, column lists indented underneath and sub-queries nested one level deeper. That makes it far easier to spot a missing join condition, a misplaced OR or a column you forgot to group by.

Example

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

becomes

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

Why the dialect setting matters

Every database extends SQL differently. Choosing the right dialect lets the formatter recognise vendor keywords and syntax instead of treating them as errors:

DialectExamples it understands
MySQL / MariaDB`backtick` identifiers, LIMIT 10, 20, ON DUPLICATE KEY UPDATE
PostgreSQL:: casts, $1 parameters, RETURNING, dollar-quoted function bodies
SQL Server (T-SQL)[bracketed] names, TOP (10), @variables, GO batches
BigQuerySTRUCT/ARRAY types, backtick project.dataset.table paths, QUALIFY
Oracle PL/SQL:bind variables, CONNECT BY, q'[…]' strings

If a query fails with a parse error, the most common cause is a dialect mismatch — try the database you actually run. The formatter is built on the open-source sql-formatter library and runs entirely in your browser, so production queries containing customer data never leave your machine.

Keyword case: upper or lower?

UPPERCASE keywords are the traditional convention and make the query structure stand out from table and column names; many modern teams prefer lowercase because it is easier to type and read. Pick one and stay consistent — linters such as SQLFluff can enforce it in CI. The Functions option controls built-ins like count() or coalesce() separately.

Comparing two versions of a query? Paste them into the Diff Checker. Exported results as JSON? Turn them into a spreadsheet with JSON to CSV.

Tools that pair well with the SQL Formatter

  • CSV to JSON — Paste CSV or TSV and get a JSON array of objects.
  • JavaScript Formatter — Unminify and pretty-print JavaScript, JSON or JSX with your preferred indentation and brace style — or strip whitespace and comments with a verified minifier.
  • HTML Formatter — Paste minified or messy markup and get clean, consistently indented HTML — including embedded <style> and <script> blocks.
  • CSS Formatter — Turn a minified stylesheet into readable CSS with one property per line and properly nested @media blocks.

Frequently asked questions

Does the formatter change what my query does?
No. Only whitespace and the letter case of keywords (and functions, if you choose) change. Identifiers, string literals and the order of everything stay the same.
Why do I get a parse error?
The formatter has to understand the SQL to lay it out. Errors usually mean the wrong dialect is selected or the statement uses syntax that dialect doesn’t support — template placeholders like {{ var }} can also confuse it.
Can I format several statements at once?
Yes. Separate statements with semicolons; each is formatted and separated by one or two blank lines depending on the “Between queries” setting.
Is it safe to paste production queries?
Yes. The formatting runs in your browser with JavaScript and nothing is sent to our server, so values in your WHERE clauses stay private.
Are stored procedures and DDL supported?
CREATE TABLE, ALTER, INSERT, CTEs (WITH) and window functions are fully supported. Procedural blocks (PL/pgSQL, T-SQL control flow) are formatted on a best-effort basis.

Related tools