SQL Formatter
Format messy SQL into readable, consistently indented queries. Supports standard SQL, MySQL, PostgreSQL, SQL Server and SQLite.
Runs in your browser. Nothing is uploaded.
About the SQL Formatter
Queries generated by ORMs, logged by a database or written in a hurry are often one long line, which makes joins, conditions and subqueries hard to follow. Formatted SQL puts each clause on its own line and indents nested parts, so you can see the logic of the query at a glance.
Consistent formatting also makes code reviews and diffs clearer and helps when you share a query with colleagues. Choosing your database dialect lets the formatter understand its syntax, such as backtick identifiers in MySQL, square brackets in SQL Server or :: casts in PostgreSQL. The query is only rewritten for readability; it is never executed.
How to use the SQL Formatter
- 1
Paste a query into the input panel, open a .sql file, or load the sample. It is formatted straight away.
- 2
Pick the dialect your database uses so its syntax (backticks, square brackets, :: casts and so on) is understood.
- 3
Choose how keywords are written and the indent size. The output updates when you change an option.
- 4
If the query cannot be parsed, the status bar shows the line and column. Use “Go to error” to jump to it.
- 5
Copy the result or download it as a .sql file.
Examples
select id, name from users where active = 1 order by nameSELECT
id,
name
FROM
users
WHERE
active = 1
ORDER BY
nameselect * from orders where customer_id in (select id from customers where country = 'NL')SELECT
*
FROM
orders
WHERE
customer_id IN (
SELECT
id
FROM
customers
WHERE
country = 'NL'
)Good to know
- Formatting only: the query is not run or checked against your schema, so a misspelt table name is not reported.
- Comments are kept, but their position may move to the start of the line.
- Vendor-specific procedural code (PL/pgSQL bodies, T-SQL control flow) is formatted as plain statements and may not look ideal.
Frequently asked questions
Which SQL dialects are supported?
Standard SQL, MySQL (also fine for MariaDB), PostgreSQL, SQL Server (T-SQL) and SQLite. Choosing the right dialect matters for quoting rules and operators that only some databases have.
Does formatting change what my query does?
No. Only whitespace, line breaks and, if you choose, the case of keywords change. Identifiers, strings and values are left exactly as written.
Can I format several statements at once?
Yes. Separate them with semicolons and each statement is formatted in turn, with a blank line between them.
Is my code uploaded to a server?
No. Processing happens entirely in your browser, in a background thread. Your input is never sent to our servers or stored anywhere.
Related tools
More tools that pair well with this one.