ToolXkit Icon

SQL Formatter

Turn one long query into readable, indented SQL.

  • Free
  • No signup
  • Nothing uploaded
  • No watermark

Input SQL

Formatted SQL

Formatted on your device as you type. Nothing is uploaded.

How to Use the SQL Formatter Online

SQL Formatter: before and after SQL A BEFORE SQL FORMATTER SQL A AFTER

A query written across one line is valid SQL and unreadable SQL. This lays it out one clause per line with nesting indented, so you can see at a glance where a WHERE ends and a JOIN begins. Strings and comments are left exactly as they are — a formatter that reformats the inside of a quoted value has corrupted your query.

No software to install Free Works on any device

Step-by-Step Guide to Using the SQL Formatter

  1. 1. Paste your query into the left box — one statement or a whole script

  2. 2. Choose your indent, and whether keywords are uppercased and columns split onto their own lines

  3. 3. The formatted SQL appears on the right as you type

    Tick “Output as HTML source” to get syntax-highlighted markup instead.

Try it now

What is the SQL Formatter?

A query written across one line is valid SQL and unreadable SQL. This lays it out one clause per line with nesting indented, so you can see at a glance where a WHERE ends and a JOIN begins. Strings and comments are left exactly as they are — a formatter that reformats the inside of a quoted value has corrupted your query.

SQL file

.SQL

Turn one long query into readable, indented SQL.

See an Example

Before

select o.id,c.name,sum(i.qty*i.price) as total from orders o join customers c on c.id=o.customer_id where o.status='paid' group by o.id

After

SELECT
  o.id,
  c.name,
  SUM(i.qty * i.price) AS total
FROM orders o
JOIN customers c
  ON c.id = o.customer_id
WHERE o.status = 'paid'
GROUP BY o.id;

Why Use SQL Tools Online?

Queries copied from logs, written in a hurry or moved between MySQL and PostgreSQL are hard to read and easy to break. These tools format, build, convert and check SQL in the page, so your schema and data stay with you.

“A well-formatted query is half debugged.”
  • Readable queries at a glance
  • INSERTs from CSV or Excel
  • Syntax errors caught early
  • Risky patterns flagged
  • Dialects converted between databases
  • JOINs and WHEREs built visually
  • Test data generated
  • Schemas kept off other servers

Popular Uses for Query Formatters

These cover the SQL chores that come up during development and reporting.

  • Formatting a long query Turn a one-line query from a log into indented SQL you can read.
  • Changing databases Convert MySQL table definitions to PostgreSQL or SQLite when moving a project.
  • Loading spreadsheet data Turn a CSV or Excel sheet into INSERT statements for a quick import.
  • Sample data Generate realistic test rows to try out a new table or report.
  • Building joins Put together a JOIN between two tables without looking up the syntax.
  • Syntax checks Catch a missing comma or bracket before running a query on the server.
  • Security review Spot patterns that may allow SQL injection in queries built from user input.
  • Query results as JSON Convert SQL rows into JSON or CSV for an app, report or spreadsheet.

What You Can Do with the SQL Formatter

One clause per line, with nesting indented

Keyword case left alone or forced upper or lower

One column per line, optionally

Strings and comments preserved exactly

Several statements formatted as a script

Why Use ToolXkit for SQL Formatter?

Your files stay with you

Everything runs inside your browser. Nothing you open or type is uploaded to a server.

Database Tools for Different Users

Backend developers

Format, check and convert queries while building features and fixing bugs.

Database administrators

Move schemas between dialects and generate index and ALTER statements.

Data analysts

Load CSV files as INSERTs and tidy long reporting queries for sharing.

SQL learners

See how SELECT, JOIN and WHERE clauses fit together by building them step by step.

QA engineers

Fill test databases with fake rows and check queries used in tests.

Report writers

Get queries explained in plain words before changing a report someone else wrote.

Best Times to Format or Convert SQL

SQL tools help when you are:

  • Reading a query from a log
  • Switching from MySQL to PostgreSQL
  • Importing a spreadsheet into a table
  • Seeding a test database
  • Reviewing a colleague’s pull request
  • Learning SQL for the first time
  • Hunting a slow report query
  • Checking code for injection risks

Frequently Asked Questions

Answers to common questions about this tool.

Will formatting change what my query does?

No. Only whitespace and line breaks move — keywords, identifiers, and the contents of strings and comments are left exactly as written. A formatter that reformats the inside of a quoted value has corrupted your query, which is why this one does not touch them.

Which SQL dialect does it understand?

The common shape of the language, which covers MySQL, PostgreSQL, SQL Server, SQLite and Oracle for ordinary statements. Vendor-specific syntax that no other engine accepts may be laid out conservatively rather than reflowed, on the principle that leaving a clause alone beats rearranging something it has misread.

Which SQL dialects does SQL Formatter support?

Most SQL tools here handle the common dialects, including MySQL, PostgreSQL, SQLite and SQL Server. Where a dialect choice matters, pick the one that matches your database before copying the result.

Is it safe to paste production queries into SQL Formatter?

As far as this site is concerned, yes. Queries are processed in your browser and are not uploaded or logged. Still avoid pasting real passwords or personal data anywhere you do not need to.

Does formatting change what my query does?

No. Formatting only changes spaces, line breaks and the letter case of keywords. The query returns the same results before and after, it is simply easier to read.

Will a converted schema work first time on the new database?

Common types and statements convert cleanly, but every database has its own features, such as special data types or functions. Review the output and test it on a copy before running it on live data.

Is SQL Formatter free without an account?

Yes. Use it as often as you like with no sign-up and no paid tier. It works in any modern browser on a work or personal computer.

Further reading

More SQL Tools

Other free tools for the same kind of job.

Browse all tools