SQL Query Formatter
Free online SQL Query Formatter that runs directly in your browser.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
SELECT
u .id,
u .email,
count (
o .id
) AS orders
FROM
users u LEFT
JOIN
orders o
ON
o .user_id = u .id
WHERE
u .status = 'active' AND (
o .created_at >= '2025-01-01' OR o .created_at IS NULL
) GROUP BY u .id,
u .email ORDER BY orders DESC,
u .email ASC;
Rate this tool:
Related tools
Other tools you may find usefulOnline SQL query formatter
SQL formatting improves query readability, facilitates code review and speeds up debugging. Our online SQL formatter adjusts indentation, line breaks and keyword casing with one click - no installation, no registration.
What is the SQL formatter used for?
Long, unformatted SQL queries are difficult to read - especially when they contain many JOINs, subqueries, or WHERE clauses with dozens of conditions. The SQL formatter rebuilds them into a readable form: each clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts on a new line, columns are indented, and keywords have consistent case. This is an essential tool when doing code reviews, documenting a database or analyzing queries submitted by another team.
How to use the SQL formatter?
Paste the raw SQL query into the "SQL Query" field. Then select the indent size (2, 4, or 8 spaces), keyword style (UPPERCASE/LOWERCASE/Keep original), and line break options for clauses and commas. Click "Format SQL" - the formatted code will appear in the right column, highlighted in the editor-like view, which you can immediately copy using the "Copy SQL" button. The statistics below the code show the number of characters and lines before and after formatting.
Indentation and line breaks
Good indentation is the basis of readable SQL. The 2-space convention is popular in front-end projects, 4 spaces - in backend and data warehouse projects, and tab - in environments where column alignment is more important than consistency with the rest of the code. The SQL formatter supports every variant. The "New Lines on Clauses" option causes SELECT, FROM, WHERE, and other main clauses to always start on a new line - making the query look like a structured document rather than a single-line string.
Keyword casing
The SQL keyword casing convention (SELECT, FROM, WHERE) is the oldest and still dominates documentation and books. However, some teams prefer lowercase letters as they are less flashy. The formatter allows you to select any style - UPPERCASE, lowercase, or keep the original - and consistently applies it to all keywords in the query, including JOINs, operators (AND, OR, NOT), and aggregate functions.
FAQ
Does the SQL formatter support podqueries and CTEs?
Yes. The formatter recognizes parentheses and indents appropriately inside subqueries. WITH expressions (CTE) are treated like normal queries - you can paste the entire WITH ... AS (...) SELECT ... block and it will be formatted as a whole.
Are my SQL queries saved somewhere?
No. Processing takes place on the server side only for the duration of formatting and is not stored anywhere. No part of your query is sent to external websites.
What is the query length limit?
The current limit is 5,000 characters, which is enough for the vast majority of real queries. If you need to format a very large SQL script, break it into smaller pieces.
Does the formatter support MySQL, PostgreSQL and other dialects?
The formatter works at the level of general SQL syntax and supports most of the constructs common to MySQL, PostgreSQL, SQLite and SQL Server: JOINs, subqueries, window functions (OVER / PARTITION BY), comments (-- and /* */), string literals and backtick-identifiers.
What does the "Keep comments" option do?
SQL comments (-- single-line and /* block */) often contain important explanations of business logic. When this option is activated, comments remain in the correct place in the formatted result. Disable it if you want "clean" SQL without comments.