SQL Formatter with Uppercase Keywords
Format and beautify SQL queries with proper indentation
What is a SQL formatter?
A SQL formatter takes a query that has collapsed into one long line — copied from application logs, an ORM's debug output, or a slow-query report — and lays it out with each major clause (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY) on its own line, with keywords uppercased for consistency. The structure of the query becomes visible: what's being selected, which tables are joined, and where the filtering happens.
Formatting runs entirely in your browser. Queries often embed real data in their literals — customer emails, IDs, internal table names — and none of it is uploaded, stored, or logged here.
When to use it
The most frequent trigger is a query you didn't write: an ORM-generated statement from Hibernate or Prisma logs, a query captured in a slow-query log, or a monster SELECT a teammate pasted into chat. Formatting it is the first step of understanding it — you can't reason about join order or spot a missing WHERE condition in a 400-character line.
It's also useful before committing: raw SQL in migrations, report definitions, and analytics notebooks lives longer than most application code, and consistent clause-per-line layout with uppercase keywords makes future diffs reviewable. When a code review comment says "what does this query actually do?", pasting a formatted version — or better, the permalink that reproduces it — usually answers the question.
Example
Paste select u.name, count(o.id) from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.name order by 2 desc and Format returns it with SELECT, FROM, LEFT JOIN, WHERE, GROUP BY and ORDER BY each starting a new line, keywords uppercased. The reshaped query makes it obvious at a glance that this is a per-user order count over active users. Use "Copy link to this result" to share a permalink that restores the exact query for whoever opens it — handy in code reviews and bug reports.
Formatting MySQL, PostgreSQL, T-SQL and Oracle queries
This formatter is deliberately simple. It doesn't parse a specific dialect: it recognises a fixed list of standard keywords — SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY, LIMIT, WITH, CASE and so on — starts the major clauses on new lines and uppercases them. Everything outside that list passes through exactly as written.
MySQL: backtick-quoted identifiers, LIMIT and OFFSET, and functions like FROM_UNIXTIME are left intact. PostgreSQL: :: casts, $1 placeholders, ILIKE and RETURNING pass through untouched, though ILIKE and RETURNING are not uppercased or given their own line. T-SQL (SQL Server): [bracketed] names, @variables and TOP survive, but a table hint such as WITH (NOLOCK) is mistaken for a CTE's WITH and pushed onto a new line — harmless, just odd-looking. Oracle: ROWNUM, NVL, CONNECT BY and :bind variables are kept as written; FETCH FIRST n ROWS ONLY is not split out.
Procedural code — PL/SQL blocks, T-SQL BEGIN/END batches, stored procedure bodies — is not laid out meaningfully. If you need dialect-aware formatting in your own pipeline, the open-source sql-formatter npm package takes a language option per dialect, and Python's sqlparse offers sqlparse.format(sql, reindent=True, keyword_case="upper").
SQL style conventions, and formatting in SSMS and VS Code
Most SQL style guides agree on the basics: uppercase keywords, lowercase snake_case identifiers, one major clause per line, and table aliases that mean something (u for users beats t1). Uppercase keywords is the convention this tool applies, and it is what makes a long query skimmable — the structure sits in capitals, the data in lowercase.
The lasting argument is leading versus trailing commas. Leading commas (, email at the start of each line) make it easy to comment out the last column and keep diffs to a single line when a column is added; trailing commas read more naturally and are what most formatters emit. Neither is wrong — pick one per codebase and let a formatter enforce it. This page doesn't impose a column-per-line layout; it focuses on clause breaks and keyword case.
In the editor: SQL Server Management Studio has no built-in formatter, so teams add one — Redgate SQL Prompt (commercial) or the free Poor Man's T-SQL Formatter. In VS Code, the mssql extension supports Format Document for T-SQL, and extensions built on sql-formatter or prettier-plugin-sql add the same command for other dialects. Use this page when the query lives outside your editor: a log, a ticket, a chat thread.
How to use the SQL Formatter with Uppercase Keywords tool
- 1
Paste your SQL
One-liners from logs, ORM debug output, or hand-written queries all work.
- 2
Format
Major clauses move to their own lines and keywords are uppercased, all locally in your browser.
- 3
Copy or share
Copy the formatted query, or copy a permalink that restores your exact input for anyone who opens it.
Frequently asked questions
Are my queries sent to a server?
No. Formatting is pure client-side JavaScript — the query never leaves your browser, which matters because production queries routinely contain real customer data in their literals.
Which SQL dialects are supported?
The formatter works on the shared core of standard SQL — SELECT/INSERT/UPDATE/DELETE, joins, grouping, CTEs via WITH — so queries for PostgreSQL, MySQL, SQL Server, and SQLite all format sensibly. It doesn't parse vendor-specific procedural extensions like PL/pgSQL or T-SQL control flow.
Does formatting change what the query does?
Normally no — only whitespace and keyword casing change, and SQL ignores both outside quotes. Two edge cases come from how this lightweight formatter works: it collapses whitespace and recases keywords across the whole text, so a keyword inside a quoted string ('select me') can be uppercased and moved to a new line, changing the literal; and a -- line comment loses its line break, so it can swallow the code that followed it. Check queries with those before running the formatted version.
Why did my keyword-named column get uppercased?
Keyword casing is applied by word matching, so an identifier that collides with a SQL keyword — a column named order, count, or values — will be uppercased along with the real keywords. Since SQL identifiers are case-insensitive unless quoted at creation time, the query still runs; adjust the casing back by hand if the style matters.
Does the formatter handle SQL comments?
Block comments (/* ... */) are kept inline and are safe. Line comments (-- ...) are risky: the formatter collapses line breaks before re-laying out the query, so code on the line after a -- comment can end up inside the comment unless it starts with a clause keyword. Convert -- comments to /* */ before formatting, or strip them.
How do I format SQL in SSMS?
SSMS has no native format command. Install an add-in such as Poor Man's T-SQL Formatter (free) or Redgate SQL Prompt, or paste the query here, format it, and paste it back. For heavy T-SQL work, VS Code with the mssql extension offers Format Document out of the box.
Should SQL keywords be uppercase?
SQL itself is case-insensitive for keywords, so it's purely a readability convention — but the most widespread one. Uppercase keywords separate the query's structure (SELECT, JOIN, WHERE) from your table and column names at a glance, which is why this formatter applies it by default.
Related on TechLogHub
Related Formatter Tools
MongoDB Query Formatter
Format and beautify MongoDB queries
XML Formatter and Validator with Error Lines
Pretty-print, minify and validate XML, keeping comments and CDATA intact
HTML Formatter with Pre and Script Preserved
Beautify messy or minified HTML while leaving pre, script, style and textarea content untouched
SQL Practice Online with 36 Graded Exercises
Graded SQL exercises and a free-query playground on SQLite in your browser
Get the next tool before you need it
One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.