How to format SQL online, free and without uploading
To format SQL, paste your query into the SQL Input box (a sample is already loaded). The Formatted Output fills in as you type. Choose Indent (2 spaces, 4 spaces or Tab), Keywords (UPPERCASE, lowercase or Preserve) and Dialect, then click Copy Formatted, or Download .sql to save formatted-query.sql. The built-in sample, one 167-character line, becomes 14 lines with each column, join and condition on its own line. Show line numbers is switched on by default.
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The formatter is a script that ships with the page, and it never connects to a database. There is no account and nothing to install.
SQL formatting, or beautifying, changes only the layout of a query: line breaks, indentation and keyword case. The meaning stays the same, and this tool checks it by reading its own output again and falling back to your original text if any token differs. It does not validate your SQL. To go the other way and squeeze a query onto one line, use the SQL minifier.
Table of Use: what the formatter does to a query
| SQL you paste | Formatted output | Note |
|---|---|---|
select a,b from t where x=1 | SELECT
a,
b
FROM
t
WHERE
x = 1 | One clause per line, one column per line, spaces around operators |
select id from users u join orders o on u.id=o.user_id | SELECT
id
FROM
users u
JOIN orders o ON u.id = o.user_id | Joins sit under FROM with the ON condition on the same line |
select * from t where x in (select y from z) | SELECT
*
FROM
t
WHERE
x IN (
SELECT
y
FROM
z
) | A subquery is indented one level deeper |
with recent as (select id from orders) select * from recent | WITH
recent AS (
SELECT
id
FROM
orders
)
SELECT
*
FROM
recent | Each CTE is its own indented block |
select case when total>100 then 'big' else 'small' end as size from orders | SELECT
CASE
WHEN total > 100 THEN 'big'
ELSE 'small'
END AS size
FROM
orders | WHEN and ELSE branches get their own lines |
select a, -- first column
b from t | SELECT
a, -- first column
b
FROM
t | A line comment stays at the end of its line, so b is not swallowed |
select id from t where note='a;b'; select 2; | SELECT
id
FROM
t
WHERE
note = 'a;b';
SELECT
2; | The ; inside the string is untouched; statements are split by a blank line |
select [a] from t (Standard SQL) | select [a] from t | Shown unchanged with a prompt to choose SQL Server (T-SQL) or SQLite |
Features
- Indent. 2 spaces, 4 spaces or Tab.
- Keywords. UPPERCASE, lowercase or Preserve, which leaves each keyword exactly as you typed it.
- Six dialects. Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle and SQLite, each with its own rules for quotes, comments and operators. A line under the options explains what the chosen dialect changes.
- Never rewrites content. Strings, comments and quoted identifiers are copied exactly, and the output is re-checked against the input.
- Scripts, not just queries. Many statements are split by a blank line, and client commands such as
DELIMITER,GO, psql backslash commands and SQL*Plus lines stay on their own lines. - Warnings with line numbers. An unclosed quote or comment is reported, and a Switch dialect button appears when your SQL looks like another database.
- Syntax highlighting and line numbers. Keywords, strings, comments, numbers and parameters are coloured, and Show line numbers can be turned off. Highlighting switches off above 3,000 output lines to keep the page responsive.
- Line and character counts for the input and the output, plus Clear and Load Sample.
How to use the SQL formatter
- Paste your SQL into the SQL Input box, or click Load Sample. Click Clear to empty the box.
- Under Formatting Options, set Indent to 2 spaces, 4 spaces or Tab.
- Set Keywords to UPPERCASE, lowercase or Preserve.
- Pick your database under Dialect. If an amber message appears with a Switch dialect button, click it to use the dialect the formatter suggests.
- Read the Formatted Output. Untick Show line numbers if you do not want them.
- Click Copy Formatted, or Download .sql to save the file.
Who can use it
- Backend developers reading a one-line query from an ORM log or a stack trace, and checking two versions in the text diff tool.
- Data analysts tidying a long query before sharing it, after renaming a table everywhere with the find and replace tool.
- Database administrators cleaning up scripts for MySQL, PostgreSQL, SQL Server, Oracle or SQLite before review, and making sample keys with the UUID generator or readable dates with the timestamp converter.
- Students learning how joins, subqueries and CTEs nest, since every level gets its own indent.
- Full-stack teams who also tidy other formats: the JSON formatter, the XML formatter, the JavaScript beautifier and the HTML beautifier.
- Reviewers who need a keyword case that matches their style guide, with the text case converter for everything that is not SQL.
FAQs
How do I format SQL online?
Paste your query into the SQL Input box. The Formatted Output appears as you type, with one clause per line and indented columns, joins and conditions. Choose Indent, Keywords and Dialect above the boxes, then click Copy Formatted, or Download .sql to save formatted-query.sql. Click Load Sample to see an example first.
Will formatting change what my query does?
No, the query logic stays the same. Only whitespace, line breaks and, if you choose, keyword case change; strings, comments, quoted identifiers, operators and numbers are copied exactly. The formatter also re-reads its output and shows your SQL unchanged if any token differs. One caveat: SQLite names an un-aliased result column after its exact text, so give computed columns an AS alias.
Which SQL dialects does it support?
The Dialect list offers Standard SQL, MySQL / MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle and SQLite. The dialect decides how quotes, comments, operators and client commands are read, for example MySQL backticks and # comments, PostgreSQL $$ bodies and :: casts, T-SQL [brackets] and GO, or Oracle q'[...]' strings and bind variables.
Why does it say my SQL is shown unchanged?
In Standard SQL the formatter spots syntax that belongs to one database, such as a MySQL # comment, [bracket] identifiers or PostgreSQL $$ quoting. Reading it wrongly could swallow part of the query, so it leaves your text alone and offers a Switch dialect button. Click it, or pick the dialect yourself, and the query is formatted.
Can it format several statements at once?
Yes. Paste a whole script and each statement is formatted separately, with a blank line between them. Semicolons inside strings and comments do not split a statement. Client commands such as MySQL DELIMITER lines, T-SQL GO and psql backslash commands stay on their own lines exactly as you wrote them.
Does it check my SQL for errors?
Only for problems that affect reading the text: an unclosed quote or an unclosed /* comment produces a warning with a line number. It does not check table names, columns or grammar, and it never connects to a database. Run the formatted query in your own database client to confirm that it works.
Is my SQL sent to a server?
It runs in your browser; nothing is uploaded (you can check the Network tab in DevTools). The formatter is a script that ships with the page, so queries containing production table names or values stay on your device. There is no account and nothing to install.