Command Palette

Search for a command to run...

SQ

SQL Formatter

Format messy SQL into readable, indented queries or minify SQL to a single line

Output will appear here...
Category:minify
Mode:Offline
Version:1.0.0
Access:Free

What is SQL Formatter?

SQL Formatter interface on Toolz.dev - Format messy SQL into readable, indented queries or minify SQL to a single line

SQL Formatter turns dense, single-line or inconsistently written SQL into readable, review-friendly queries. It puts each major clause - SELECT, FROM, WHERE, JOINs, GROUP BY, ORDER BY, HAVING, LIMIT, UNION - on its own line, breaks SELECT columns onto separate lines, indents AND/OR conditions under their clause, and normalizes keyword casing to upper or lower. The result is the kind of layout you would want in a code review: a 400-character query from an ORM log becomes a structure you can scan for the missing join condition.

As a SQL query formatter it takes a line like select top 10 [Order ID], total from dbo.[Order Details] where total > 100 and status = 'open' and returns SELECT TOP 10 on the first line, [Order ID] and total on their own indented lines, then FROM, then WHERE with the AND condition indented under it. SQL Server users can treat it as a SQL formatter for SSMS: format the T-SQL in this online SQL formatter, then paste it back into SQL Server Management Studio. It is a web page, not an SSMS extension, so there is nothing to install.

Under the hood it is a real tokenizer, not a pile of find-and-replace rules. String literals (including doubled-quote and backslash escapes), double-quoted and backtick-quoted identifiers, bracketed SQL Server identifiers, numbers, operators and both comment styles (-- line and /* block */) are lexed as atomic tokens before any layout decision is made. That means a column value like 'SELECT * FROM users' inside a string is never mistaken for a clause, and formatting can restructure whitespace without ever corrupting literal content.

The Minify mode does the opposite: it collapses a formatted query to a single line - dropping comments, preserving every literal byte-for-byte - which is handy for log grepping, packing queries into JSON payloads or .env files, and comparing query shapes. Everything runs client-side in your browser, so production queries containing table names, customer data in literals or schema details are never uploaded, logged or stored anywhere.

Formatting is tokenizer-based rather than regex-based, so string literals and comments containing SQL keywords are not reformatted as if they were code. Dialects still differ in ways no formatter can settle, particularly around quoting identifiers, so the output is normalised rather than guaranteed portable.

How to use SQL Formatter?

1

Paste your SQL

Drop in any query - a one-liner from an ORM debug log, a hand-written report query, or a multi-statement script separated by semicolons.

2

Pick keyword case and indentation

Choose UPPERCASE or lowercase for keywords and 2, 4 or 8 spaces of indentation to match your team conventions.

3

Click Format or Minify

Format produces clause-per-line output with SELECT columns on their own lines and AND/OR conditions indented. Minify collapses everything to a single line with comments removed and literals untouched.

4

Copy or download

Copy the result to your clipboard for a code review or migration file, or download it as a .sql file.

Key Features

Tokenizer-based, literal-safe

String literals, quoted identifiers and comments are lexed first - formatting can never alter data inside quotes

Clause-aware line breaks

SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, HAVING, LIMIT and UNION each start a new line, with subqueries indented by nesting depth

Keyword case normalization

A comprehensive keyword list (DML, DDL, functions, types) is converted to UPPER or lower case; identifiers are left exactly as written

One SELECT column per line

Comma-separated select lists break onto individual indented lines, making wide queries diffable in pull requests

Frequently Asked Questions

Yes. The tokenizer understands the syntax both dialects share plus their quoting differences: backtick identifiers and backslash string escapes for MySQL, double-quoted identifiers, :: casts and JSON operators like -> and ->> for PostgreSQL. Bracketed [identifiers] from SQL Server are handled too. Dialect-specific statements it does not recognize are still formatted safely, because unknown tokens are passed through untouched.

Comments

0 comments

0/2000 characters

No comments yet. Be the first to share your thoughts!

sql formatterformat sqlsql beautifiersql pretty printsql minifierformat sql query onlinesql indentationuppercase sql keywordsmysql formatterpostgresql formattersql query formattersql formatter onlineonline sql formattersql formatter for ssms