Text UtilitiesText FormattersFree Tool

SQL Formatter

Reformat SQL by inserting a line break before each major keyword — a broad keyword list covering joins, clauses, and DDL statements.

How to Use SQL Formatter
  1. 1Paste your SQL query
  2. 2Click Convert
  3. 3Copy the reformatted query with keyword line breaks
About SQL Formatter

What this SQL formatter does

Long SQL written on one line is hard to read. This tool inserts a line break before each major SQL keyword, so a query is laid out as separate clauses. For example select name, total from orders where total > 100 order by total becomes one line for the select list, one for from, one for where and one for order by.

Keywords that start a new line

The formatter breaks before SELECT, FROM, WHERE, JOIN (with LEFT, RIGHT, INNER and OUTER), ON, AND, OR, NOT, IN, LIKE, BETWEEN, ORDER BY, GROUP BY, HAVING, LIMIT, OFFSET, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM, CREATE TABLE, ALTER TABLE, DROP TABLE, UNION, UNION ALL, AS, DISTINCT and the aggregate names COUNT, SUM, AVG, MAX and MIN. Matching is case-insensitive, and the keyword's original capitalisation is kept.

What it is good for

  • Making a query from a log file or ORM debug output readable.
  • Getting an overview of the clauses and joins in a query someone else wrote.
  • Preparing a query for a code review, ticket or document.

What it does not do

  • No indentation of nested queries. Subqueries are split into lines but not indented under their parent.
  • Aggressive line breaking. Because AND, OR, IN, AS and function names such as COUNT also trigger breaks, simple expressions can be split across several lines.
  • Keywords inside strings. A string literal such as 'this and that' contains the word AND and may be broken. Check string values after formatting.
  • No dialect awareness. It does not validate syntax and treats MySQL, PostgreSQL, SQL Server and Oracle queries the same way.
  • It never changes meaning on purpose. Only whitespace is added, but always run the formatted query in a safe environment before relying on it.

Habits that make SQL easier to read

  1. Put each selected column on its own line when there are more than three or four.
  2. Write join conditions directly under the join they belong to.
  3. Use meaningful table aliases (o for orders, c for customers) rather than t1, t2.
  4. Name columns explicitly instead of using SELECT * in production queries.

Never paste queries that contain real customer data or credentials into any online tool unless you trust it; this one runs locally in your browser, but get into the habit of using placeholder values. Related: the JSON formatter for API payloads.

Frequently Asked Questions

A broad list covering query clauses (SELECT, FROM, WHERE, ORDER BY, GROUP BY, HAVING, LIMIT), joins (JOIN, LEFT, RIGHT, INNER, OUTER, ON), logic (AND, OR, NOT, IN, LIKE, BETWEEN), DDL/DML (INSERT INTO, UPDATE, DELETE FROM, CREATE TABLE, ALTER TABLE, DROP TABLE), and aggregate functions (COUNT, SUM, AVG, MAX, MIN).

No — it's a flat keyword-based line-breaker, not a full SQL parser. Nested subqueries and complex expressions won't get smart contextual indentation.

No — it doesn't check for syntax errors or verify table/column names against a real schema.

No — the reformatting happens entirely in your browser; it never connects to a database.

Related Tools

Related Articles

More from Text Utilities