Home/Tools/Developer Tools/SQL Formatter

SQL Formatter

Developer Tools

Format and beautify SQL queries with proper indentation.

⚡ Instant🔒 Private, in your browser🆓 Free, no sign-up👥 For developers
Your data never leaves your browser. We do not store inputs.

What SQL Formatter does

The SQL Formatter reformats SQL queries with consistent indentation, line breaks and keyword case for standard SQL, MySQL, PostgreSQL, SQLite, SQL Server, Oracle, MariaDB, BigQuery and Snowflake. It understands strings, comments, function calls and nested queries, so the layout changes but the query does not.

FV
Reviewed by the FreeToolsVerse team · Last updated · How we check our tools

Features and benefits

  • Supports nine dialects: standard SQL, MySQL, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, MariaDB, BigQuery and Snowflake
  • Choose uppercase, lowercase or preserved keywords and a 2-space, 4-space or tab indent
  • Puts each clause on its own line and each selected column on its own line, so diffs are easy to read
  • Runs in your browser, so table and column names are not uploaded

How to use SQL Formatter

  1. Paste your SQL
  2. Choose the dialect, keyword case and indentation
  3. Click Format
  4. Copy or download the formatted query

Who should use it

Made for developers. Typical uses:

  • Formatting complex SQL queries for readability
  • Standardizing SQL formatting across teams
  • Debugging SQL syntax with formatted output

Example

The one-line query select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=true group by u.id,u.name order by orders desc is laid out with SELECT and three indented columns, FROM users u with LEFT JOIN orders o ON o.user_id = u.id, then WHERE, GROUP BY and ORDER BY each on their own lines, with keywords in capitals.

Limitations and accuracy

It formats layout only; it does not validate table names or run the query. Very unusual vendor-specific syntax may be reported as an error.

Accuracy: Output is tested against known inputs. For production code, review the result and run your own tests.

Expert Tip

Choose the dialect of your database. Quoting rules and operators differ (backticks in MySQL, square brackets in SQL Server, :: casts in PostgreSQL), and the right dialect lets the formatter read them correctly.

Frequently asked questions

How do I use the SQL Formatter?
Paste your query, choose the dialect, keyword case and indent, and click Format. Copy the result or download it as formatted.sql.
Which databases are supported?
Standard SQL, MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, MariaDB, BigQuery and Snowflake.
Does formatting change what the query does?
No. Strings, comments and function calls are preserved, and only whitespace, line breaks and keyword case change.
Does it run or validate my query?
No. It does not run the query or check that tables and columns exist, and very unusual vendor-specific syntax may be reported as an error.
Is my SQL uploaded anywhere?
No. Formatting runs in your browser.

SQL Formatter: the complete guide

What the formatter does

The SQL Formatter turns a long query on one line into a consistently laid out one, with each clause on its own line, joins aligned and columns listed one per line. It supports standard SQL, MySQL, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, MariaDB, BigQuery and Snowflake. You also choose the keyword case (upper, lower or preserved) and the indent (2 spaces, 4 spaces or tabs). The query is processed in your browser, so your table and column names are not uploaded.

A worked example

The one-line query select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.active=true group by u.id,u.name order by orders desc is laid out like this. SELECT is followed by three indented lines, u.id, u.name and count(o.id) AS orders. FROM, then users u, then LEFT JOIN orders o ON o.user_id = u.id. WHERE, then u.active = TRUE. GROUP BY with u.id and u.name on separate lines, and finally ORDER BY orders DESC. The keywords are in capitals and spaces are added around operators.

Why dialect matters

SQL is not one language. Quoting rules, function names and operators differ between databases: MySQL uses backticks around names, SQL Server uses square brackets, PostgreSQL has operators such as :: for casts and -> for JSON, and BigQuery has its own syntax for arrays and structs. Choosing the right dialect helps the formatter read those correctly. If your query uses vendor-specific syntax and fails in Standard SQL, try the dialect of your database.

What it does not do

Formatting is purely cosmetic. The tool does not run the query, check that tables and columns exist, or find logic errors, and it does not optimise performance. Very unusual syntax may be reported as an error. Strings, comments and function calls are preserved, so the query means the same thing before and after.

Habits that help

Consistent layout makes queries easier to review. Put each selected column on its own line, so that a diff shows exactly what changed, and keep keywords in capitals so that they stand out from table and column names. Before you share a query, remove any real customer data from literals. If your query output ends up as JSON, the JSON Formatter and JSON to CSV Converter help present it, and the YAML Formatter and XML Formatter tidy other formats.

Limits

The formatter handles one pasted script at a time. Procedural extensions, such as long stored procedures, can have unusual layout rules, and comments may be moved slightly to fit the layout. Always read the formatted query before you run it against a live database, and keep the formatted version in version control, so that later changes show up as small, readable differences instead of one long changed line.

Learning resources

Explore more in Developer Tools, read the guides and articles, or see how we test our tools.

Share This Tool