Skip to content
CODE FORMATTING & MINIFICATION

SQL Formatter & Beautifier Online

Put SQL clauses on separate lines with uppercase keywords.

  • Free
  • No signup
  • Runs in your browser

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

SQL Formatter

About SQL Formatter

Long SQL written on one line is hard to review. The SQL formatter collapses extra whitespace and starts a new line at each major clause: SELECT, FROM, JOIN variants, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, VALUES, SET, INSERT INTO, UPDATE and DELETE FROM. Those keywords are written in uppercase.

Table names, column names, functions and conditions are left as you typed them. It works for MySQL, MariaDB, PostgreSQL and SQLite style queries and is useful when you debug queries copied from logs or from WordPress plugin code.

How to use SQL Formatter

  1. Paste a SQL query into the input box.
  2. Click Run Tool. Each clause appears on its own line.
  3. Copy the result into your editor or documentation.

Example

Input

select id, name, email from users u left join orders o ON o.user_id = u.id where u.active = 1 order by name limit 10

Output

SELECT id, name, email
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.active = 1
ORDER BY name
LIMIT 10

Common uses

  • Reading a slow query copied from a MySQL slow log.
  • Preparing SQL for a code review or a tutorial.
  • Understanding the structure of a query produced by an ORM or plugin.

Privacy and safety

This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.

Frequently asked questions

Does it validate my SQL?

No. It only reformats text and does not connect to a database or check that table and column names exist.

Are spaces inside quoted strings preserved?

Repeated spaces are collapsed everywhere, including inside quoted string values. Check queries that depend on exact spacing in a literal.

Does it indent subqueries?

Subqueries start on new lines at each clause keyword, but they are not indented. For deeply nested queries, use a full SQL formatter in your database client.

Learn to build this yourself

Free tutorials and courses on NHP Learning cover PHP, JavaScript, SQL and WordPress, from the basics to real projects.