SQL Formatter
Beautify messy SQL into readable, consistently indented statements. Pick a dialect and keyword casing — formatting runs entirely in your browser.
Paste your SQL
Result
What does a SQL formatter do?
A SQL formatter rewrites a query with consistent indentation, line breaks and spacing so the structure of joins, subqueries and CASE blocks is visible at a glance. It is the quickest way to turn a one-line statement copied out of a log, an ORM or a query builder into something a human can review.
The formatter is dialect-aware, which matters more than it sounds. MySQL backticks, PostgreSQL casts, BigQuery arrays and Transact-SQL TOP all parse differently, so the parser is told which database the query targets before it touches the text. That keeps identifiers, operators and literals exactly as written while it reflows the whitespace around them.
Nothing is executed and nothing is sent anywhere: the statement is parsed and reprinted in your browser. Formatting does not change what the query does — identifiers, operators, literals and their order are preserved, and the text inside string literals is never touched. Keyword casing changes only when you ask for it. When you are about to commit a reformatted query, paste the before and after into the [text diff](/diff) tool so the real changes are easy to spot.
How to format SQL
- Paste your query into the input box — single statements and long scripts both work.
- Choose the dialect your database uses: standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, BigQuery, Snowflake, Transact-SQL, PL/SQL or Redshift.
- Choose the keyword case: upper for the classic style guide, lower for teams that prefer it, or preserve to leave the query's own casing alone.
- Press Format SQL.
- If the dialect does not match the syntax, the formatter reports a parse error with the position; switch the dropdown and run it again.
- Copy the result, download it as a .sql file, or compare it against the original in the [diff tool](/diff) before you commit.
SQL formatting examples
One-line SELECT with a join
select u.id,u.name from users u join orders o on o.user_id=u.id where o.total>100 order by o.total desc;
SELECT u.id, u.name FROM users u JOIN orders o ON o.user_id = u.id WHERE o.total > 100 ORDER BY o.total DESC;
CTE written on one line
with recent as (select id,total from orders where created_at>'2026-01-01') select count(*) from recent where total>100;
WITH
recent AS (
SELECT
id,
total
FROM
orders
WHERE
created_at > '2026-01-01'
)
SELECT
count(*)
FROM
recent
WHERE
total > 100;Subquery in a WHERE clause
select * from users where id in (select user_id from orders where total>500) and active=true;
SELECT
*
FROM
users
WHERE
id IN (
SELECT
user_id
FROM
orders
WHERE
total > 500
)
AND active = TRUE;Window function report
select customer_id, row_number() over (partition by customer_id order by created_at desc) as rn from orders;
SELECT
customer_id,
row_number() OVER (
PARTITION BY
customer_id
ORDER BY
created_at DESC
) AS rn
FROM
orders;Transact-SQL query
select top 10 name, created_at from dbo.users where deleted_at is null order by created_at desc;
SELECT TOP 10 name, created_at FROM dbo.users WHERE deleted_at IS NULL ORDER BY created_at DESC;
SQL formatter: UrsaKit vs other options
| Criterion | UrsaKit | Rolling your own | Typical online tool |
|---|---|---|---|
| Setup | Open the page | Install and run a CLI | Open the page |
| Dialect awareness | 10 dialects on one page | One dialect per tool | Varies |
| Data leaves the device | No, runs in the browser | No | Often sent to a server |
| Options | Dialect and keyword case | Full CLI flags | Usually keyword case only |
| Keyword casing | Upper, lower or preserve | Configurable | Often fixed |
| Sign-up required | No | No | Sometimes |
Frequently asked questions
Which SQL dialects are supported?
Ten options in the dropdown: standard SQL plus MySQL, MariaDB, PostgreSQL, SQLite, BigQuery, Snowflake, Transact-SQL, PL/SQL and Redshift. Pick the one your database uses, because the parser applies that dialect's rules for quoting and syntax.
Does formatting change my query?
No. Only whitespace and line breaks move: identifiers, operators, literals and their order are preserved, and the text inside string literals is never touched, so 'Ada' or an escaped quote comes back exactly as written. Keyword casing changes only when you choose upper or lower — pick preserve to leave it untouched. One caveat: placeholders the parser does not recognise, such as PostgreSQL's %s or $1, can be respaced or dropped, so check the diff before pasting the query back into code.
Why do I get a syntax error?
The formatter parses the statement with the dialect you selected, so unbalanced quotes, or syntax that belongs to another database — MySQL's [b] identifiers under PostgreSQL, for example — can raise a parse error. The message names the dialect and the position; switch the dropdown and run it again.
Is my SQL uploaded?
No. Formatting runs locally in JavaScript in your browser.
Can I keep keywords lowercase?
Yes. Choose lower to force everything down, or preserve to keep the casing the query already had.
Does it work offline?
Yes. After the page loads, formatting makes no further network requests.
How do I format SQL in VS Code, DBeaver or DataGrip?
In VS Code, install an SQL formatter extension and run Format Document with Shift+Alt+F on Windows or Linux, or Shift+Option+F on macOS. DBeaver reformats the SQL editor with Ctrl+Shift+F, and DataGrip and the other JetBrains IDEs use Code → Reformat Code (Ctrl+Alt+L, or Cmd+Option+L on macOS). For a server or a CI pipeline, sqlfluff and the sql-formatter command line are the usual options.