Skip to content

SQL Formatter

Make SQL readable in one paste with your database dialect and style.

Keywords
More options
Indent
Runs in your browser — your data is not uploaded.

How to use

  1. Click Paste to insert your query into the SQL box.
  2. Choose your database in Dialect.
  3. Set Keywords to UPPER, lower, or Preserve.
  4. Click Format SQL to update the result.
  5. Click Copy to copy the formatted SQL.

Examples

Format a customer order summary

Input
select c.id, c.name, count(o.id) as order_count from customers c left join orders o on o.customer_id = c.id where c.state = 'CA' group by c.id, c.name order by order_count desc;
Output
SELECT
  c.id,
  c.name,
  count(o.id) AS order_count
FROM
  customers c
  LEFT JOIN orders o ON o.customer_id = c.id
WHERE
  c.state = 'CA'
GROUP BY
  c.id,
  c.name
ORDER BY
  order_count DESC;

Lowercase keywords, 4-space indent and AND after the condition in SQL Server

Input
SELECT TOP 10 [id], [name] FROM [dbo].[customers] WHERE [active] = 1 AND [state] = 'TX' ORDER BY [id] DESC;
Output
select
    top 10 [id],
    [name]
from
    [dbo].[customers]
where
    [active] = 1 and
    [state] = 'TX'
order by
    [id] desc;

Minify a query and remove comments

Input
-- Monthly sales report
SELECT region, SUM(total) AS revenue
FROM orders /* completed orders only */
WHERE status = 'paid'
GROUP BY region;
Output
SELECT region, SUM(total) AS revenue FROM orders WHERE status = 'paid' GROUP BY region;

FAQ

Is my SQL sent to a server?

Your query is processed in your browser and is not sent to a server or saved by the tool. Only option settings are saved locally; analytics events contain the tool slug, not your SQL.

Why do I get a SQL parse error?

Check the syntax at the reported line and column, and make sure Dialect matches your database. After an error, the previous result stays visible but is marked Outdated.

Can I upload a large SQL file?

Upload accepts .sql and .txt files up to 10 MB. For input larger than 200 KB, automatic formatting stops; run it manually with Format SQL or Ctrl+Enter.

What is the SQL formatter keyboard shortcut?

Press Ctrl+Enter to update the result.

Can I format SQL with template placeholders?

In Format mode, placeholders such as {{ column }}, {% condition %}, and ${ value } are protected and restored unchanged.