SQL Formatter

Free SQL formatter. Beautify a SQL query by putting major clauses on their own lines, normalizing commas and joins, and adding a trailing semicolon.

AI-ready Use this tool with AI

This tool has a free JSON API. Copy a prompt or skill below to use it with ChatGPT, Claude, or any AI agent — no API key needed.

API docs
Paste your SQL above.

How sql formatter works

SQL written in one long line is hard to read and review. A formatter breaks it into a standard layout: each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY, joins) on its own line, continuation columns indented, commas normalised, and a trailing semicolon added.

This formatter recognises the common SQL clauses — SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, the join types, and INSERT/UPDATE/DELETE/CREATE keywords — and places each on a new line with a fixed indent. It normalises comma spacing in select lists and tidies JOIN spacing so LEFT OUTER JOIN reads consistently.

Paste your SQL and click Format. The tool returns a readable, consistently indented query. It handles standard SELECT, INSERT, UPDATE, DELETE, and DDL statements; very dialect-specific syntax may not be perfectly pretty-printed but will still be cleaner than a single line.

Frequently asked questions

Which SQL dialects are supported?
The formatter targets standard SQL clauses used across MySQL, PostgreSQL, SQLite, SQL Server, and Oracle. It is keyword-based rather than a full parser, so it works on most queries but may not perfectly indent every dialect-specific construct.
Does it add a semicolon?
Yes. If the query does not end with a semicolon, the formatter adds one; if it already ends with one, it is kept and not doubled.
Will it validate my SQL?
No. The formatter only rewrites the layout; it does not parse or check the query against a schema. Use it to make SQL readable before running it in your database.
How are joins formatted?
Join keywords are normalised so "LEFT OUTER JOIN" or "left join" both read consistently, and each join is placed on its own line for clarity.