Skip to main content

SQL - Formatting tool

Easily clean up unreadable, legacy SQL code with a simple formatting tool. Make your SQL queries instantly readable and kickstart your code review process.

· 2 min read
View raw
Christophe
Markdown, WSL and Docker lover ~ Insatiably curious.
Cet article existe aussi en français — lire la version française.

This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.

SQL - Formatting tool

⚡
TL;DR

This article introduces the author's free, self-hosted SQL Formatter tool (source on GitHub, hosted demo at sql-formatter.avonture.be), which turns unreadable single-line legacy SQL queries into properly indented, readable statements — a useful first step before reviewing old database code.

When faced with legacy code, it is often useful to reformat it to make it readable. And from there, the study of the code can begin.

There are plenty of reformatting tools for json, php, javascript and other languages, but far fewer for a query written in SQL.

Just copy/paste SELECT LAT_N, CITY, TEMP_F FROM STATS, STATION WHERE MONTH = 7 AND STATS.ID = STATION.ID ORDER BY TEMP_F in the tool and get

SELECT
LAT_N,
CITY,
TEMP_F
FROM
STATS,
STATION
WHERE
MONTH = 7
AND STATS.ID = STATION.ID
ORDER BY
TEMP_F

Retrieve my SQL Formatter tool and sources on https://github.com/cavo789/sql_formatter.

The tool is accessible online: https://sql-formatter.avonture.be/

Demo

I've built a couple of similar self-hosted, single-purpose tools: JSON - Online linter and Excel Formula Beautifier.


Was this article helpful?
Did you try the steps in this article?