Esta página ainda não foi traduzida para o português, por isso aparece em inglês.

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.

Atualizado em
 
Formatted SQL
 

Seus dados nunca saem do seu computador. Todo o processamento acontece localmente no navegador.

Como usar: 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 recognize 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.

Também pesquisado como: sql beautifier, format sql, sql pretty print, sql query formatter, mysql formatter, postgresql formatter, t-sql formatter, bigquery formatter.

Ferramentas que combinam com: SQL Formatter

  • Formatação JSON — Cole o JSON aqui para formatá-lo, compactá-lo ou validá-lo.
  • 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.

Perguntas frequentes

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.
Posso instalar o SQL Formatter como um aplicativo da web e usá-lo offline?
Sim. O SQL Formatter é um aplicativo da web instalável (PWA) — instalado a partir do seu navegador, não baixado de uma loja de aplicativos. Clique em “Instalar aplicativo” na parte superior desta página no Chrome ou no Edge (Windows, macOS, Linux, ChromeOS) ou, no Android, use “Compartilhar” → “Adicionar à tela inicial” no iPhone e no iPad, ou “Arquivo” → “Adicionar ao Dock” no Safari 17+ em um Mac. Em seguida, ela se abre em uma janela própria com seu próprio ícone e, como é executada inteiramente no seu navegador, continua funcionando offline. O Firefox no desktop não permite a instalação de aplicativos da web. Como funciona a instalação.

Ferramentas relacionadas