SQL Query Formatter
Format SQL as you type: one column per line, joins and conditions on their own lines, subqueries indented. Strings and comments never change.
Format SQL as you type: one column per line, joins and conditions on their own lines, subqueries indented. Strings and comments never change.
Used SQL Query Formatter? Share how it went to help others.
About this tool
SQL Query Formatter turns a long, one-line query into one you can read. Paste the SQL and the formatted version appears as you type. Every column gets its own line, joins and their conditions are lined up, AND and OR start new lines, and subqueries, common table expressions and CREATE TABLE columns are indented. A short CASE stays on one line and a long one is split at WHEN and ELSE. Short lists such as IN (1, 2, 3) stay together. You choose how keywords look: uppercase, lowercase, or left as you wrote them. You can indent with two spaces, four spaces or a tab, and put commas at the end or at the start of the line, which some teams prefer because adding a column changes only one line. The formatter reads the query piece by piece instead of replacing words in the text, so the contents of strings, quoted names, dollar-quoted blocks and comments are never touched. The word and inside a piece of text stays as it is, and so do double spaces in it. After formatting, the result is compared with your query: if anything other than spacing or the case of keywords were different, the tool would show your original text and tell you. It understands the syntax shared by MySQL, MariaDB, PostgreSQL, SQLite and SQL Server for everyday queries, including backticks and square brackets around names, PostgreSQL casts with two colons and JSON operators, window functions, and placeholders such as $1, :name and @id. Turn on the MySQL option if your comments start with a # sign. Several statements separated by semicolons are formatted one after another with a blank line between them. Very long stored procedures are kept correct but are not indented as finely as queries. The tool only formats: it does not run the query or check that tables and columns exist. You can open a .sql file, copy the result or download it, and everything happens in your browser, so queries with customer data or internal table names are not uploaded.

Paste a query or open a .sql file.
Keyword case, indent and comma position.
It is formatted as you type.
Use it in your editor, code or documentation.
No button to press.
Text, names and comments never change.
Compared with your query after formatting.
Keyword case, indent and commas.
Readable queries are easier to fix
Make a one-line query from a log readable.
ExampleA 20-column query becomes a list you can scan.
See which condition belongs to which join.
ExampleAn extra AND under a LEFT JOIN stands out.
Give every query the same shape.
ExampleUppercase keywords and two spaces in every pull request.
Show clean SQL in a guide or ticket.
ExampleCopy the formatted query into your wiki.
See the order of the clauses.
ExampleSELECT, FROM, WHERE, GROUP BY and ORDER BY each start a line.
Read a generated CREATE TABLE.
ExampleOne column per line with its type and constraints.
Small habits that help
Agree on keyword case and comma position in your team and keep to it.
Formatting does not check tables, columns or logic. Run the query on test data.
If the indentation looks wrong near the end, a bracket is probably missing.
With commas at the start of the line you can comment out any column but the first.
Senior Software Engineer · Developer of Toolyconvert
Hemant developed SQL Query Formatter and tests it on desktop and mobile with real files. He is a senior software engineer from Dehradun, India, building websites since 2014, and designed and developed Toolyconvert end to end.
Last updated 24 November 2026
Featured on
Toolyconvert is listed on these product directories and launch platforms.