✓ Formatted · text in quotes and comments unchanged
About the SQL Formatter
Turn a long one-line SQL query into readable SQL: each clause (SELECT, FROM, WHERE, JOIN, GROUP BY…) on its own line, selected columns listed one per line, conditions lined up under WHERE and subqueries indented. Text in quotes and comments are never changed, so the query does exactly what it did before.
How to use it
- Paste one or more queries into the Input box.
- Choose Format or One line, the indent, and whether keywords should be UPPERCASE, lowercase or as typed.
- Read the result on the right.
- Copy or download it.
Tip: Formatting only changes spaces, line breaks and the capitals of keywords. Table names, column names, values in quotes and comments come out exactly as you wrote them.
How a formatted query is laid out
- One clause per line
- SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line.
- Columns listed
- Each selected column, GROUP BY and ORDER BY item and SET assignment goes on its own line, indented, so it's easy to add or remove one.
- Conditions lined up
- Each AND or OR in WHERE, HAVING and ON starts an indented line; BETWEEN x AND y stays together.
- Joins
- Each JOIN (INNER, LEFT, RIGHT, FULL, CROSS) starts a line with its ON condition.
- Subqueries indented
- A SELECT inside brackets is laid out one level deeper, with its closing bracket lined up under it.
Why text and comments are never changed
The formatter reads the query the way a database does: it knows where a quoted string such as 'Rock and Roll' starts and ends, including doubled quotes ('it''s'), and where comments are. The words and spaces inside them are never re-spaced or put in capitals, and a -- comment keeps its own line so it can't hide the rest of the query.
Quoted names in "double quotes", `backticks` or [brackets] (PostgreSQL, MySQL and SQL Server style) are kept as written, as are PostgreSQL casts like price::numeric and $$ … $$ text.
One line: for code and logs
One line squeezes the query onto a single line for a string in your code, a log or a command line. Because a -- comment would swallow everything after it on one line, line comments are turned into /* … */ comments, which close themselves.
Writing readable SQL
Give tables short aliases (users u, orders o) and always use them; name columns you select instead of SELECT *; put each join condition next to its JOIN; and use a WITH (common table expression) for a long subquery so it reads from top to bottom. Formatting makes each of these easy to see.
Before and after
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 and o.total > 100 group by u.id
becomes SELECT on its own line with u.id and count(o.id) AS orders indented below it, FROM users u, LEFT JOIN orders o ON o.user_id = u.id, WHERE u.active = 1 with AND o.total > 100 indented under it, and GROUP BY with u.id below. Nothing about what the query does has changed.
Common SQL mistakes formatting reveals
- A missing JOIN condition
- A JOIN line with no ON makes every row match every other row.
- AND and OR without brackets
- a = 1 OR b = 2 AND c = 3 means a = 1 OR (b = 2 AND c = 3); the indented lines show where brackets are needed.
- A column in SELECT but not in GROUP BY
- With both lists one item per line, a missing column is easy to see.
Tips and tricks
Format both versions first so the diff shows real changes, not spacing.
Paste the SQL an ORM logged (Django, Rails, Prisma) to see what it really runs.
With each JOIN on its own line, a join without ON stands out.
Separate them with ; and each is formatted with a blank line between.
Choose lowercase keywords; table and column names are never changed either way.
Queries with customer names or values are formatted in your browser and never uploaded.
Questions
Does it change what my query does?
No, only spacing and capital letters on keywords; your table names, values and logic stay the same.
Which databases does it support?
Standard SQL as used by MySQL, PostgreSQL, SQLite, SQL Server, Oracle and others, including their quoted names and PostgreSQL casts.
Are my comments kept?
Yes, exactly as written. In One line mode, -- comments become /* */ so they don't cut off the rest of the query.
Can it format several queries?
Yes. Separate them with semicolons.
Can I keep keywords lowercase?
Yes. Choose lowercase or as typed in the Keywords list.
Does it check my SQL for errors?
No. It formats the text; your database tells you about mistakes. Formatting often makes them easier to spot.
Does it format stored procedures?
Simple procedures format well; very long scripts with procedural blocks may need tidying by hand.
Which SQL dialects does the formatter support?
It works with the SQL shared by MySQL, PostgreSQL, SQLite, SQL Server and Oracle: SELECT, INSERT, UPDATE, DELETE, joins, subqueries, CTEs and common functions. Quoted names with " ", backticks or [ ] and PostgreSQL casts like x::int are kept as written.
Does formatting change what my query returns?
No. Only spaces, line breaks and, if you choose, the case of keywords change. Text in quotes, names and numbers stay exactly the same, so the database runs the same query.
Can I format several queries at once?
Yes. Separate them with semicolons; each statement is formatted on its own with a blank line between them.
Is my code uploaded?
No. The tool runs in your browser; what you paste never leaves your device and nothing is stored on a server.
Related tools
Updated