SQL Formatter
Beautify, indent, format, and minify SQL queries with customizable casing and spacing.
Runs in your browser. Nothing you add is uploaded.
What the SQL Formatter does
Paste a SQL query that arrived on one line, from an ORM log, a slow-query report or an error message, and this formatter puts each clause (SELECT, FROM, each JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT and so on) on its own line, indents the lines in between, and sets keywords to upper case, lower case or leaves them as typed. String literals and comments are never altered, so a value like 'it''s -- not a comment' comes through intact. Minify does the reverse, collapsing the query to a single line without comments.
How to format SQL
- Paste your query, or load a preset: a JOIN with GROUP BY, an INSERT, a CTE with window functions, or an UPDATE with a subquery.
- Choose keyword casing: UPPERCASE, lowercase or preserve.
- Choose indentation: 2 spaces, 4 spaces or a tab.
- Turn on Minify for a one-line version without comments.
- Copy the result, or download it as query.sql (query.min.sql when minified).
The SQL Formatter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.
When to use it
Reading ORM-generated queries
Hibernate, Django, Prisma and ActiveRecord log queries as one long line full of aliased columns. Breaking it at each clause shows at a glance which tables are joined and what the WHERE conditions are, which is often enough to spot the unexpected JOIN or missing LIMIT behind a slow request.
Consistent queries in code review
Migrations and report queries written by different people drift into different styles. Running them through the same casing and indentation before committing means the diff shows real changes rather than whitespace.
One-line queries for scripts
Some places need a query on a single line: a psql -c argument, a cron entry, a JSON config value. Minify removes line breaks and comments and keeps every string literal exactly as written.
Good to know
- Formatting never changes what a query does; databases ignore whitespace and keyword case. String contents and quoted identifiers are left alone.
- A line comment (-- note) keeps its own line, so nothing that followed it is accidentally commented out.
- The formatter is deliberately simple: it breaks lines at clauses, but does not put each selected column on its own line or indent nested subqueries by depth.
- It is dialect-neutral text processing, so PostgreSQL, MySQL, SQLite and SQL Server syntax pass through, but it does not check that the query is valid.
- Minify removes all comments, including optimizer hints written as /*+ … */ in MySQL and Oracle. Format instead of minifying if you need to keep them.
Frequently asked questions
Why should SQL keywords be in uppercase?
Does this tool work offline?
Does formatting alter the query execution plan?
Does it check my SQL for errors?
Page last updated . Found a wrong result or a mistake on this page? Let us know.
Related tools
Regex Builder
Build a regular expression from blocks, with live matches.
Chmod Permissions Calculator
Work out chmod values from checkboxes, octal or ls -l strings.
CSS Box Shadow Generator
Multi-layer CSS box shadows with live preview and Tailwind export.
Glassmorphism Generator
Design frosted-glass panels and copy the CSS or Tailwind classes.