Tip: press Ctrl+Enter (⌘+Enter on a Mac) in the editor to format.
What this SQL formatter does
It reads your SQL the way a database would - as tokens, not as text - and lays it out consistently: one clause per line, indented select lists, aligned joins, and the keyword casing you prefer. Comments stay where you put them and string literals are never touched.
- Dialect-aware. T-SQL
[brackets]and@variables, PostgreSQL$$bodies and::casts, MySQL`backticks`- each dialect is read with its own rules. - Safe by design. The output is re-checked token by token against your input. If anything but whitespace and casing would change, you get your SQL back untouched.
- Private. Formatting happens in your tab. Nothing is uploaded, logged or stored.
- Minify too. Need one line for a log, a JSON payload or a command line? Minify collapses the query while keeping literals and optimizer hints intact.
Examples
T-SQL formatter: a SQL Server report query
select top 5 o.[OrderID],c.CompanyName,sum(od.UnitPrice*od.Quantity) as Total from dbo.Orders o inner join dbo.Customers c on c.CustomerID=o.CustomerID inner join [Order Details] od on od.OrderID=o.OrderID where o.OrderDate>='2024-01-01' group by o.OrderID,c.CompanyName order by Total desc
SELECT TOP 5
o.[OrderID],
c.CompanyName,
SUM(od.UnitPrice * od.Quantity) AS Total
FROM dbo.Orders o
INNER JOIN dbo.Customers c ON c.CustomerID = o.CustomerID
INNER JOIN [Order Details] od ON od.OrderID = o.OrderID
WHERE o.OrderDate >= '2024-01-01'
GROUP BY
o.OrderID,
c.CompanyName
ORDER BY
Total DESC
PostgreSQL formatter: a CTE
with recent as (select customer_id, count(*) as n from orders where created_at > now() - interval '30 days' group by customer_id) select c.email, r.n from customers c join recent r using (customer_id) where r.n >= 3 order by r.n desc limit 20;
WITH
recent AS (
SELECT
customer_id,
COUNT(*) AS n
FROM orders
WHERE created_at > NOW() - interval '30 days'
GROUP BY
customer_id
)
SELECT
c.email,
r.n
FROM customers c
JOIN recent r USING (customer_id)
WHERE r.n >= 3
ORDER BY
r.n DESC
LIMIT 20;
Both outputs use the Standard style with 4-space indents. Switch the style to Compact for denser SQL or Expanded for leading commas and one item per line. The formatter docs cover the details.
SQL formatter FAQ
Is this SQL formatter free?
Yes. It is free to use with no sign-up and no usage limits. It is the formatter from the SQLly desktop app, published as a free web tool.
Is my SQL sent to a server?
No. The formatter is compiled to WebAssembly and runs inside your browser tab. Your SQL is never uploaded, logged or stored, and once the page has loaded it keeps working offline.
Which SQL dialects does it support?
T-SQL for SQL Server and Azure SQL, PostgreSQL, MySQL and MariaDB, SQLite and Oracle. Snowflake and Redshift are formatted with the PostgreSQL rules and BigQuery with the MySQL rules. Auto-detect picks T-SQL when it sees [bracketed] names or @parameters, MySQL when it sees `backticks`, and PostgreSQL otherwise.
Can formatting break my query?
It is built not to. After formatting, SQLly checks its output token by token against your input. If anything other than whitespace and the casing you asked for would change, it gives your SQL back exactly as you wrote it. SQL that does not parse cleanly, such as an unterminated string, is also left untouched.
How do I keep part of a query exactly as written?
Wrap it in -- formatter:off and -- formatter:on comments. Everything between them passes through untouched, which is handy for hand-aligned lists or generated code.
Can I format SQL automatically while I work?
Yes, in the SQLly desktop app for macOS, Windows and Linux. Run Format SQL from the Query menu or the command palette, or turn on Format on save and Format on paste, with dozens of layout settings to match your team’s style.
Like the formatter? Meet the rest of SQLly
A native SQL workbench for macOS, Windows and Linux with IntelliSense that knows your schema, guardrails for risky queries, and this formatter built into the editor.