Skip to content

Developer Tools

SQL Formatter

Breaks a query onto multiple lines at SELECT, FROM, WHERE, and other keywords for easier reading.

  • Free
  • No sign-up
  • Runs in your browser

Guide

What SQL formatting is

SQL is free-form: a database does not care whether a query sits on one line or twenty. People do care. A long query on one line, such as one copied from an application log or generated by an ORM, is hard to scan. Formatting breaks the query into lines so each clause starts in the same place, making it easier to see what is selected, from where, and under which conditions.

This tool takes a simple approach. It collapses all whitespace to single spaces and then starts a new line before a fixed list of keywords: SELECT, FROM, WHERE, AND, OR, GROUP BY, ORDER BY, HAVING, LIMIT, the JOIN variants (JOIN, INNER JOIN, LEFT JOIN and RIGHT JOIN), UNION, INSERT INTO, VALUES, UPDATE, SET and DELETE FROM.

When it helps

You might use it when debugging a slow query pulled from a log, reviewing SQL that a teammate pasted into chat, documenting a query, or just making a hand-written one readable before you add to it. Splitting at AND and OR makes it easy to read conditions one at a time, and seeing each JOIN on its own line makes the table relationships clearer.

Queries that mix with other data formats come up too, for example when you export results as JSON and want to pretty-print them with the JSON Formatter.

How to format SQL with this tool

  1. Paste or type your query into the box labeled SQL query. An example single-line query is already there.
  2. The Formatted box updates automatically with one clause per line.
  3. Click Copy to copy the formatted text. There is no download button and no settings for indentation or keyword case.

The text is handled in your browser and is not uploaded. The tool never connects to a database or runs your query.

What it does not do

This is a keyword line-breaker, not a full SQL parser, so it is simpler than a dedicated formatter. Lines are not indented: a column list stays on the SELECT line, and nested subqueries are not indented under their parent, though a SELECT inside a subquery does start a new line.

Keywords that begin a new line are written in uppercase, but other words keep whatever case you typed. A SELECT at the very start of the query is left in its original case, because only keywords preceded by whitespace are matched. For example, a lowercase select at the beginning stays lowercase while the later FROM and WHERE become uppercase.

The tool does not recognize quoted strings or comments. A keyword that appears as a standalone word inside a string literal may cause a line break there, and AND inside a BETWEEN range also starts a new line. Line comments that run to the end of a line will be merged onto the line with the rest of the query, because whitespace is collapsed first, so remove such comments before formatting. Always check the output before running it.

Frequently asked questions

Does it change what my query does?

It only changes whitespace and the case of the keywords it breaks on, which does not affect meaning in standard SQL. The exception is a keyword inside a quoted string, which can be altered, so check string values.

Does it support specific database dialects?

It has no dialect settings. It just recognizes a fixed list of common keywords, so it works on typical SELECT, INSERT, UPDATE and DELETE statements but does not understand dialect-specific syntax.

Why is my first SELECT still lowercase?

The tool only matches keywords that follow a space, and the first word of the query has none before it. Later keywords are uppercased, but the opening one keeps your original case.

Is my query sent anywhere?

No. Formatting runs in your browser and nothing is executed or uploaded.