Text Utils
By ToolzBank Team•
2 min read
•Monday, October 19, 2026•Updated Monday, October 19, 2026

How to Format SQL Queries (MySQL, PostgreSQL and More)

Readable SQL is easier to debug and review. Learn simple formatting conventions and beautify any query for MySQL, PostgreSQL, SQL Server and more.

#sql formatter#format sql#sql beautifier#mysql

SQL generated by an ORM, copied from a log or written in a hurry often arrives as one long line. Formatting it — one clause per line, consistent indentation, consistent keyword case — makes the logic visible, so mistakes in joins and conditions stand out.

Before and after

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.status = 'active' group by u.id, u.name order by orders desc;
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.status = 'active'
GROUP BY
  u.id,
  u.name
ORDER BY
  orders DESC;

Conventions worth following

  • Start each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) on a new line.
  • Put one selected column per line, so changes show up clearly in code review.
  • Use one keyword case consistently — uppercase keywords are the most common convention.
  • Give tables short, meaningful aliases and use them everywhere.

How to format a query

  1. Open the SQL Formatter.
  2. Choose your dialect: Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark or Trino.
  3. Paste the query, pick keyword case (UPPER, lower or unchanged) and indent size, and click Format.
  4. Need the opposite? "One line" compacts a query while leaving string literals untouched.

Formatting only changes whitespace and keyword case — table names, values and logic stay the same. It does not check your table or column names against a database, so run the query to confirm it works.

Frequently Asked Questions

Does formatting change what my SQL query does?

No. Only whitespace, line breaks and optionally keyword case change; the query logic stays the same.

Why choose a SQL dialect?

Databases have different syntax, such as backtick identifiers in MySQL or square brackets in SQL Server. Choosing the dialect lets the formatter understand it.

Should SQL keywords be uppercase?

It is the most common convention because it separates keywords from table and column names, but any case works as long as it is consistent.

Is my SQL uploaded?

No. Formatting happens in your browser.