SQL prettify and format

What is a Sql Prettify?

SQL copied from logs, ORMs or one-line strings in code is hard to read: joins, conditions and subqueries all run together. Formatting it with consistent line breaks and indentation makes it easy to understand, review and debug. This tool formats SQL for many dialects.

How to use it

  1. Paste the SQL query.
  2. Choose the dialect, such as PostgreSQL, MySQL, SQL Server (T-SQL), BigQuery, Oracle PL/SQL or SQLite.
  3. Set options like keyword case and indentation.
  4. Copy the formatted query.

Example

Input:

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=1 group by u.id,u.name having count(o.id)>5 order by orders desc

Output:

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 = 1
GROUP BY
  u.id,
  u.name
HAVING
  COUNT(o.id) > 5
ORDER BY
  orders DESC

Why the dialect matters

Dialects differ in identifier quoting (backticks in MySQL, double quotes in PostgreSQL, square brackets in SQL Server), keywords and functions. Choosing the right dialect prevents the formatter from misreading syntax such as :: casts in PostgreSQL or @variables in T-SQL.

Readability tips

  • Use uppercase keywords and lowercase identifiers for contrast.
  • Put each selected column and each join on its own line, so diffs are clear.
  • Use meaningful table aliases rather than single letters in long queries.
  • Formatting never changes query results; it only changes whitespace and keyword case.

Queries are formatted locally, so production SQL with sensitive table names stays private.

Frequently Asked Questions

Does formatting change what my SQL query does?

No. Only whitespace, line breaks and keyword case change. The query logic and results are the same.

Which SQL dialects are supported?

Common dialects including standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, BigQuery, Oracle PL/SQL and DB2, depending on the options shown.

Why does the formatter break on my query?

The selected dialect may not match your SQL. Choose the correct dialect, or check for syntax errors.

Should SQL keywords be uppercase?

It is a convention, not a requirement. Uppercase keywords make queries easier to scan.