SQL Formatter Online — Beautify and Indent SQL Queries Free
A SQL formatter online takes unformatted, minified, or single-line SQL queries and reformats them with proper indentation, line breaks, and keyword capitalisation. Readable SQL is faster to debug, easier to review in pull requests, and less likely to hide logical errors in how clauses relate to each other.
Why SQL Formatting Matters
SQL queries generated by ORMs, query builders, or logging tools often arrive as long single-line strings — all whitespace stripped, keywords mixed-case, no alignment between select columns or join conditions. Reading and debugging these queries requires mentally re-parsing the structure on every read.
Consistently formatted SQL follows a predictable visual pattern: major clauses (SELECT, FROM, WHERE, GROUP BY, ORDER BY) start on new lines at the left margin; column lists and conditions are indented; subqueries have their own indentation level. This structure makes it immediately obvious how many joins are in the query, where the filtering happens, and what the output columns are.
How to Use the SQL Formatter
- Paste your SQL. Copy the SQL query from your database tool, application log, or code file and paste it into the input area.
- Select the SQL dialect. Choose MySQL, PostgreSQL, T-SQL (Microsoft SQL Server), or standard SQL. Different dialects have slightly different reserved words and syntax conventions.
- Format. Click Format. The output appears in the result panel with proper indentation, keyword casing, and clause alignment.
- Copy the formatted query. Use the formatted SQL in your database tool, code review, or documentation.
SQL Formatting Conventions
| Element | Convention | Example |
|---|---|---|
| Keywords | UPPERCASE | SELECT, FROM, WHERE, JOIN |
| Table and column names | lowercase or snake_case | users, created_at, order_id |
| Clause alignment | Left-aligned at column 0 or right-aligned to a column | SELECT / FROM / WHERE |
| Column list | One column per line when more than 3–4 columns | SELECT id, name, email |
| JOIN conditions | ON clause on the same line or indented one level | JOIN orders ON users.id = orders.user_id |
| Subqueries | Indented one level relative to the outer query | Wrapped in parentheses with inner SELECT indented |
Before and After: Formatting in Action
An unformatted query from an ORM log might look like this:
select u.id,u.name,u.email,o.total from users u inner join orders o on u.id=o.user_id where o.status='completed' and o.created_at > '2026-01-01' order by o.total desc limit 50After formatting:
SELECT
u.id,
u.name,
u.email,
o.total
FROM users u
INNER JOIN orders o
ON u.id = o.user_id
WHERE
o.status = 'completed'
AND o.created_at > '2026-01-01'
ORDER BY o.total DESC
LIMIT 50The formatted version immediately shows: two tables involved, one join condition, two WHERE filters, and a sort with a result limit.
SQL Dialects and Their Differences
MySQL
MySQL uses backtick quoting for identifiers (`table_name`) and supports LIMIT x OFFSET y syntax. Common in web stacks with PHP, Ruby on Rails, and WordPress.
PostgreSQL
PostgreSQL uses double-quote identifiers ("table_name") and single-quoted string literals. It supports advanced features like CTEs (WITH clauses), window functions, and JSON operators. The formatter handles PostgreSQL-specific syntax like :: type casting.
T-SQL (Microsoft SQL Server)
T-SQL uses bracket quoting for identifiers ([table_name]) and has different pagination syntax (OFFSET ... FETCH NEXT ... ROWS ONLY). It also supports TOP instead of LIMIT.
Common Questions
Does the formatter validate my SQL?
A formatter applies purely cosmetic transformations — it does not execute the SQL or validate it against a schema. Syntax errors in the query may produce garbled output or prevent formatting. For query validation and execution, use a database client (DBeaver, TablePlus, pgAdmin, MySQL Workbench) connected to a development database.
Should I store formatted SQL in code?
Yes. Raw SQL strings in application code should follow the same formatting conventions as any other code. Multi-line SQL with consistent indentation is far easier to review in code diffs and easier to modify without introducing errors. Use a SQL formatter as part of your code review process for any query that spans more than one line.
Format Your SQL Now
Paste any unformatted SQL query and get properly indented, readable SQL instantly — supports MySQL, PostgreSQL, T-SQL, and standard SQL. Free, no signup.
Open SQL Formatter