SQL Formatter

Paste a messy or one-line SQL query and get it back with each clause on its own line and everything indented. Pick your database dialect, choose the indentation, and copy the clean result. Everything runs in your browser, so your query stays on your device.

Indent
Result

What a SQL formatter does

SQL queries often get written or copied as one long line, which is hard to read and easy to make mistakes in. A formatter rewrites the query with each clause on its own line and the parts indented, so the structure of the query is clear at a glance. It does not change what the query does, only how it is laid out. This tool formats your SQL for the database you choose and can put the keywords in uppercase.

Why use our SQL formatter

  • ·Free. No signup, no paywall, no limits.
  • ·Runs in your browser. Your query is never uploaded, so it is safe for private schemas.
  • ·Many dialects. MySQL, PostgreSQL, SQLite, SQL Server, and BigQuery are all supported.
  • ·Your house style. Choose the indentation and whether keywords are uppercase.
  • ·Syntax highlighting. The editor colours your SQL so it is easy to scan as you work.

SQL formatter options

Format

Rewrites your query on multiple lines with each clause on its own line and the parts indented. Long, one-line queries become easy to read and review.

Beforeselect id,name from users where active=1AfterSELECT id, name FROM users WHERE active = 1

Dialect

Pick the database you are writing for, such as MySQL, PostgreSQL, SQLite, or SQL Server. The formatter follows that dialect's keywords and quoting.

BeforeMySQL, PostgreSQL, SQLite, SQL Server...AfterFormatted for your chosen database

Uppercase keywords

Writes SQL keywords like SELECT, FROM, and WHERE in capitals, which is the common house style. Turn it off to keep your keywords exactly as typed.

Beforeselect id from usersAfterSELECT id FROM users

Indent

Choose 2 or 4 spaces for each level of indentation, so the result matches the style used in the rest of your project.

Before2 spaces or 4 spacesAfterYour choice per level

Why the SQL dialect setting matters

Databases agree on the basics but differ in the details, especially in how they quote names. Picking the right dialect helps the formatter read your query the way your database will:

DatabaseQuotes names withExample
MySQLBackticksSELECT `order` FROM `sales`
PostgreSQL and SQLiteDouble quotesSELECT "order" FROM "sales"
SQL ServerSquare bracketsSELECT [order] FROM [sales]

Text values use single quotes in every dialect: WHERE name = 'Sam'. Standard SQL works for most simple queries when you are not sure which dialect you have.

A formatter does not check your query

The formatter only changes the layout. It does not know your tables, so a query that formats cleanly can still fail when you run it because of a misspelled column or a missing table. It will even lay out an unfinished query like SELECT * FROM without complaint.

Formatting is still one of the best ways to find mistakes by eye. Once each clause is on its own line, a missing join condition, a stray comma, or a filter in the wrong place is much easier to spot.

When to format SQL

A formatter helps any time a query is hard to read. These are the cases that come up most:

  • ·Reading a query from a log. Paste a one-line query pulled from an app log to see its structure.
  • ·Cleaning up before review. Format a query so a teammate can read it in a pull request.
  • ·Debugging a long join. Lay out a big query so you can follow every join and condition.
  • ·Learning SQL. See how a query breaks into clauses while you are still learning.

Frequently asked questions

What is a SQL formatter?
A SQL formatter takes a query that is on one line or has messy spacing and rewrites it with each clause on its own line and the parts indented. It does not change what the query does, only how it looks, so it is easier to read, review, and debug.
How do I format a SQL query?
Paste your query into the input box, pick your database dialect and indentation, then click Format. The clean version appears below. Click the copy button to copy it, or download it as a .sql file.
Which SQL dialects are supported?
You can format standard SQL, MySQL, PostgreSQL, SQLite, SQL Server (Transact-SQL), and BigQuery. Pick the one that matches your database so keywords and quoting are handled correctly.
Does the formatter change my query?
No. It only changes spacing, line breaks, and the case of keywords. The tables, columns, conditions, and logic stay exactly the same, so the formatted query returns the same results as the original.
Can it uppercase the keywords?
Yes. Uppercase keywords is on by default, so SELECT, FROM, WHERE, and the rest come out in capitals. Turn it off if you prefer to keep your keywords lowercase or exactly as you typed them.
Is my SQL kept private?
Yes. All formatting runs in your browser. Your query is never uploaded to a server or saved anywhere, so you can safely paste in SQL that references private tables or data. Once the page has loaded you can even use it offline.