---
title: "How to format SQL queries | ToolSugar"
description: "Turn a one line SQL query into readable, indented code. Choose a dialect and keyword case, and fix common formatting errors."
canonical: https://toolsugar.com/blog/how-to-format-sql
image: https://toolsugar.com/og.png
---

# How to format a SQL query so you can read it

Updated 2026-11-09

To format a SQL query, put each clause on its own line and indent what belongs under it. SQL Formatter on ToolSugar does this in your browser with the sql-formatter library. Choose your database dialect and keyword case, and the readable version appears as you paste.

[Open SQL Formatter](https://toolsugar.com/tools/sql-formatter)

## Format a SQL query in four steps

Paste the query or open a .sql file. The formatted text updates live.

1. Paste your query into the SQL box, or open a .sql file.
2. Pick a Dialect that matches your database.
3. Choose UPPER, lower or Keep as typed under Keyword case.
4. Copy the result, or press Download to save formatted.sql.

## Which dialect should you pick

The list covers Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle PL/SQL, BigQuery and Snowflake. The dialect tells the tokenizer which quoting, operators and keywords are valid, so a backtick name or a double colon cast is read the right way.

If you are unsure, choose the database the query will run on. Standard SQL is the fallback for code that you move between systems.

## Keyword case and what stays the same

Upper case keywords such as SELECT and WHERE make the structure easy to scan. Lower case matches the style of many modern codebases. Keep as typed leaves your choice alone.

Only whitespace and keyword case change. Table names, column names and string literals stay as written, and comments in the query are kept. The query returns the same rows before and after.

## When the formatter shows an error

The formatter has to split the query into tokens before it can lay it out. An unclosed quote or bracket stops that process. A feature from another database can also fail.

Check the ends of strings and parentheses first. Then switch the dialect to the one that matches your database and try again.

## Questions

### Can I format a query that has comments?

Yes. Comments in the query are kept in the output, so notes you left for your team stay in place.

### How much does each level indent?

Two spaces per level. Subqueries and conditions move in by that step under their clause.

### Does formatting make a query faster?

No. The database ignores extra whitespace, so layout affects people who read the query and has no effect on how it runs.

[Open SQL Formatter](https://toolsugar.com/tools/sql-formatter)

## Related guides

- [How to format JSON online](https://toolsugar.com/blog/how-to-format-json)
- [How to convert CSV to JSON](https://toolsugar.com/blog/how-to-convert-csv-to-json)
- [How to convert JSON to CSV](https://toolsugar.com/blog/how-to-convert-json-to-csv)
- [How to convert XML to JSON](https://toolsugar.com/blog/how-to-convert-xml-to-json)
