How to Format SQL Queries
- Paste your SQL query into the text area above. If you're in a different mode, the tool auto-detects SQL and suggests switching.
- Select your dialect from the dropdown — MySQL, PostgreSQL, BigQuery, SQLite, T-SQL, or Standard SQL. Toggle “UPPERCASE keywords” on or off.
- Copy the formatted result. Click “Copy Clean Text” or press
Ctrl+K. You can also download it as a.sqlfile.
Before and After
Here's a typical query before and after formatting. The input is a single line — the output is structured, indented, and easy to read.
select u.id,u.name,o.total from users u inner join orders o on u.id=o.user_id where o.status='active' and o.total>100 order by o.total descSELECT
u.id,
u.name,
o.total
FROM
users u
INNER JOIN orders o ON u.id = o.user_id
WHERE
o.status = 'active'
AND o.total > 100
ORDER BY
o.total DESCWhy Format SQL?
Unformatted SQL is one of the biggest obstacles to productive code review. A 200-character single-line query hides its logic — the joins, the filter conditions, the grouping, and the ordering are all crammed together. Reviewers have to mentally parse the query before they can evaluate whether it's correct. Formatted SQL makes the structure immediately visible: each clause gets its own line, joins are aligned, and subqueries are indented. This cuts review time dramatically and catches bugs like missing join conditions or incorrect WHERE clauses.
Formatting is equally critical for debugging. When a query returns unexpected results or times out, the first step is understanding what it actually does. A formatted query lets you trace the data flow: which tables are joined, what filters are applied, how results are grouped and sorted. Complex queries with CTEs (WITH clauses), window functions, and nested subqueries are essentially unreadable without proper indentation. The formatter handles all of these structures, giving you a clear view of even the most complex analytics queries.
UPPERCASE Keywords
The convention of uppercasing SQL keywords — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY — is one of the most widely followed practices in SQL development. It creates a clear visual distinction between the structural keywords that define the query's shape and the user-defined names (tables, columns, aliases) that define its content.
Most SQL style guides recommend uppercase keywords, including Simon Holywell's SQL Style Guide, GitLab's SQL guidelines, and Kickstarter's SQL style guide. The formatter uppercases keywords by default. If your team prefers lowercase keywords, uncheck the “UPPERCASE keywords” option to preserve the original casing.
Privacy & Database Security
SQL queries often contain sensitive information: table names reveal your data model, column names expose what data you collect, and WHERE clauses can contain literal values like user IDs, email addresses, or API keys. Pasting these into an online tool that uploads them to a server is a security risk.
Unformat.online processes all SQL entirely in your browser. The formatting library runs as JavaScript — your queries are never sent over the network, never stored on disk, and never logged. There are no server-side endpoints, no databases, and no analytics on query content. You can verify this by opening your browser's Network tab: zero requests are made during formatting.
This makes Unformat.online safe for production queries, internal analytics, database migrations, and any SQL containing proprietary schema or sensitive data.
Frequently Asked Questions
Are my SQL queries sent to a server?
No. All formatting happens in your browser using JavaScript. Your queries never leave your device. This is critical for queries containing sensitive table names, column values, or business logic.
Which SQL dialects are supported?
Standard SQL (ANSI), MySQL, PostgreSQL, BigQuery, SQLite, and T-SQL (Microsoft SQL Server). Select the dialect from the dropdown above the text area to get dialect-specific keyword recognition and formatting.
Can I format multiple SQL statements at once?
Yes. Separate your statements with semicolons and the formatter will format each one individually, with blank lines between them for readability.
Does formatting change the meaning of my query?
No. Formatting only adds whitespace and line breaks. The actual SQL tokens — keywords, identifiers, operators, and literal values — are never modified. The formatted query is semantically identical to the original.