What is SQL Formatter?
This SQL formatter makes long, single-line SQL queries readable. ORMs, logs and query builders often produce SQL as one long line; paste it here and the formatter puts every major clause, such as SELECT, FROM, WHERE, JOIN, GROUP BY, HAVING, ORDER BY and LIMIT, on its own line, uppercases those keywords and indents AND and OR conditions under the WHERE clause.
The result is easier to read, review and debug, and ready to paste into a pull request, a ticket or your database client. It works with the common SQL used by MySQL, PostgreSQL, SQL Server, SQLite and Oracle.
How to use SQL Formatter
- Paste your SQL query into the input panel.
- The formatted query appears in the output panel straight away.
- Check that each clause starts on its own line and conditions are indented.
- Copy the formatted SQL or download it.
Key features
- Puts SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY and more on separate lines
- Uppercases SQL keywords
- Indents AND and OR conditions
- Collapses messy whitespace from logs and ORMs
- Works across MySQL, PostgreSQL, SQL Server, SQLite and Oracle
- Runs in your browser; queries are never uploaded
Common use cases
- Reading SQL generated by ORMs such as Hibernate, Prisma, Django or ActiveRecord
- Formatting slow queries from database logs before analyzing them
- Making SQL readable in code reviews, tickets and documentation
- Tidying hand-written queries before saving them
- Comparing two versions of a query more easily
Technical details & standards
The formatter collapses all whitespace, then starts a new line before each major keyword: SELECT, FROM, WHERE, AND, OR, GROUP BY, ORDER BY, HAVING, LIMIT, UNION, INSERT INTO, VALUES, UPDATE, SET, DELETE and the JOIN variants (JOIN, LEFT JOIN, RIGHT JOIN, INNER JOIN). These keywords are written in uppercase, and AND and OR lines are indented by two spaces.
It is a lightweight, keyword-based formatter rather than a full SQL parser, so it is fast and dialect-neutral but not syntax-aware: a keyword that appears inside a string literal or identifier is also moved to a new line, and subqueries are not indented separately. Review the output before running it against production data.
Frequently asked questions
How do I format a SQL query?
Paste the query into the input panel; the formatted version appears instantly with each clause on its own line. Most database IDEs (DBeaver, DataGrip, SSMS) also have a format shortcut, often Ctrl+Shift+F.
Which SQL dialects does the formatter support?
It formats the common clauses shared by MySQL, PostgreSQL, SQL Server, SQLite and Oracle. Because it works by keyword rather than a dialect-specific parser, vendor-specific syntax is kept as is.
Does formatting change what my query does?
It only changes whitespace and the case of SQL keywords, which SQL ignores. The exception is text inside string literals: if a string contains a keyword such as 'from', it is affected too, so check queries with such strings.
How do I format SQL Server (T-SQL) queries?
Paste the T-SQL and each major clause (SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY) is moved to its own line with keywords uppercased. The formatter is keyword-based, so T-SQL specifics such as TOP, square-bracket names and variables are kept as written, and subqueries are not indented separately. In SSMS you can also format with a plugin or a shortcut set up in your editor.
How do I format Oracle SQL?
Paste the query and the common clauses are put on separate lines with uppercase keywords. It does not parse PL/SQL blocks or Oracle-only syntax, which are left as written, so use it for SELECT, INSERT, UPDATE and DELETE statements and review the result for anything vendor-specific.
Is this an alternative to desktop SQL formatters and IDE plugins?
For a quick one-off format, yes: nothing to install, and the query never leaves your browser. Desktop formatters and IDE plugins offer dialect-aware parsing, subquery indentation and configurable style rules, which this lightweight formatter does not, so use them for team-wide style enforcement.
Should SQL keywords be uppercase?
SQL is case-insensitive for keywords, but uppercase keywords with lowercase table and column names is the most widespread convention, because it makes the query structure easy to scan.
Is my data safe?
Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.
Does it work offline?
Once the page has loaded, this tool can process input without an internet connection.