Skip to content
useToolz online tools

SQL форматтер онлайн

Sign in or register to save tools to favorites

A tool for formatting and minifying SQL queries.

Formatting adds line breaks and indentation for SQL keywords: SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, and others.

Nested parentheses automatically receive an additional indentation level.

Minification removes all extra whitespace and comments, compressing the query into a single line.

All major SQL dialects are supported: MySQL, PostgreSQL, SQLite, SQL Server.

SQL Formatter and Minifier Online

A free online tool for formatting and minifying SQL queries. Paste your query, choose an indentation style — and get a readable, neatly formatted code or a compact single-line version.

Why format SQL

SQL queries generated by ORMs, copied from logs, or written in a hurry are often a single long line without indentation. Such code is hard to read, debug, and maintain. The SQL formatter transforms an unreadable query into structured text with logical line breaks and indentation.

Well-formatted SQL is not just aesthetics. It is the ability to quickly find an error in a WHERE clause, spot a redundant JOIN, or understand the grouping order. For team code reviews, formatting is mandatory.

How the formatter works

The tool analyzes the SQL query by tokens: it recognizes keywords, string literals, parentheses, commas, and semicolons. String literals in single quotes, double quotes, and backticks are handled separately — their content is not modified.

Formatting algorithm:

  1. Tokenization preserving string literals
  2. Whitespace normalization in non-string parts
  3. Line breaks before top-level keywords
  4. Indent increase on open paren, decrease on close paren
  5. Sub-keyword indentation (AND, OR, ON)

SQL keywords

GroupKeywordsBehavior
Primary operatorsSELECT, FROM, WHERE, HAVING, LIMITNew line, no indent
JOIN operatorsJOIN, LEFT JOIN, RIGHT JOIN, INNER JOINNew line, no indent
Grouping/sortingGROUP BY, ORDER BYNew line, no indent
Sub-keywordsAND, OR, ON, WHEN, THEN, ELSENew line, 2-space indent
Subqueries( ... )Increase indent level
Enumerations, (comma)New line continuation

Query minification

Minification is the reverse task: remove all extra whitespace, line breaks, and comments, compressing the query into a single line. Useful for:

  • Passing SQL via HTTP requests or query strings
  • Storing queries in configuration files
  • Comparing queries during performance A/B testing
  • Generating queries in code without extra line breaks

The tool correctly handles string literals during minification — spaces inside strings are not removed.

Supported dialects

The formatter works with the syntax of all major DBMS:

  • MySQL / MariaDB — backticks for identifier quoting: `table_name`
  • PostgreSQL — double quotes: "column_name"
  • SQLite — compatible with MySQL and PostgreSQL syntax
  • SQL Server (T-SQL) — square brackets not supported, use double quotes
  • Oracle SQL — basic syntax is supported

FAQ

Does the formatter change query logic? No. It only changes whitespace and keyword casing. Logic, values, and operation order remain unchanged.

Can I format multiple queries at once? Yes — paste multiple queries separated by semicolons. Each ; starts a new formatted query on a new line.

What about stored procedures? The formatter targets DML/DDL queries. Complex procedures with BEGIN/END may not format perfectly.

See also: JSON Formatter · Diff (text compare) · JS Minifier · CSS Minifier

We use cookies for site operation and analytics. Подробнее

Upscaled image
Download

Log in to continue

or