Skip to content
SQL

SQL Formatter

Pretty-print or minify SQL queries.

-- active users with their most recent order SELECT u.id, u.name, o.total FROM users u JOIN orders o ON o.user_id = u.id WHERE u.active = 1 AND o.total > 100 AND u.name <> 'select' -- literal text is never re-cased ORDER BY o.total DESC LIMIT 10;

This tool recognizes MySQL, PostgreSQL, and SQL Server identifier-quoting styles ("…", `…`, […]) at the same time, so there's no dialect switch to worry about. String literals, quoted identifiers, and comments are never rewritten in either mode. Parentheses are only broken onto new indented lines when they contain a SELECT (a subquery); ordinary function-call parentheses stay inline. Everything runs entirely in your browser; your query is never sent anywhere.

About SQL Formatter

An SQL formatter pretty-prints queries with consistent indentation and line breaks, or minifies them by stripping whitespace and comments—helpful for code review and readable logs. toco.tools's SQL formatter has no dialect selector. Instead, it recognizes all three common quoted-identifier styles at once — `"postgres style"`, `` `mysql style` ``, and `[SQL Server style]` — along with both common string-escaping conventions (doubled `''` and backslash `\'`). A dedicated tokenizer breaks the query into meaningful units before formatting, so keyword-like text inside string literals, comments, or quoted identifiers is never mistaken for an actual keyword and rewritten. Major clauses (SELECT, FROM, WHERE, JOIN, and more) each start a new line; AND/OR break onto their own indented line inside WHERE/HAVING. Comma-separated items in SELECT, GROUP BY, and ORDER BY are split one per line by default (toggleable), and parentheses only open a new indent level when they contain a SELECT (i.e., a subquery). This is a practical formatter for readability, not a full SQL parser, so vendor-specific functions and stored-procedure syntax aren't specially handled. Always validate against your database before running in production.

How to use

  1. Paste your SQL
  2. Choose keyword case and indent width
  3. Format or minify, then copy

FAQ

What is an SQL formatter?

A tool that pretty-prints or minifies SQL for readability or compactness.

Can I choose a MySQL / PostgreSQL / SQL Server dialect?

There's no dialect selector. Instead, all three quoted-identifier styles ("…", `…`, […]) and string-escaping conventions are recognized at once, so you can just paste your query. Vendor-specific functions and procedural syntax are not specially handled.

Could the contents of strings or comments get rewritten?

No. A dedicated tokenizer identifies string literals, quoted identifiers, and comments before any formatting happens, so their contents are never altered in either Format or Minify mode.

What happens with broken or invalid SQL?

Unclosed string/identifier quotes or comments show an error and leave the output empty. Merely unbalanced parentheses don't error — the tool formats what it can, since pasting partial query fragments is common.

Is uploaded data sent externally?

No. All processing runs in your browser; nothing is sent to toco.tools servers.