About the SQL Formatter
Long one-line queries from logs or ORMs are hard to read. Format them into clear, indented SQL so you can review and debug them quickly.
SQL copied from an ORM log, a monitoring tool or a colleague’s message often arrives as a single unreadable line. Formatting it puts each clause on its own line, indents joins and sub-queries and makes the structure visible, which is the first step in reviewing or optimising a query. This formatter is for backend developers, data analysts and database administrators.
Choose the dialect so dialect-specific syntax is understood: standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle PL/SQL, BigQuery and others. Choose keyword case (upper, lower or as typed) and the indent. Only whitespace and keyword case change; identifiers and values are left exactly as they were, so the query does the same thing after formatting.
How to use the SQL Formatter
- 1Paste your SQL.
- 2Pick the database dialect and keyword case.
- 3Copy the formatted query.
Key features
- Dialect-aware formatting for many databases.
- UPPER, lower or original keyword case.
- 2 spaces, 4 spaces or tab indentation.
- Handles joins, sub-queries and CTEs.
- Runs locally with no upload.
Practical uses
- Reviewing a slow query from logs.
- Cleaning up SQL before putting it in a pull request.
- Making long reporting queries readable for colleagues.
- Preparing SQL snippets for documentation.
Example
select u.id,u.name,count(o.id) from users u left join orders o on o.user_id=u.id group by u.id,u.name becomes a query with SELECT, FROM, LEFT JOIN and GROUP BY on separate lines, columns listed one per line and the join condition indented beneath it.
Tips and common mistakes
- Pick the right dialect: backticks, square brackets and $1 parameters are read differently by each.
- Format before diffing two versions of a query so only real changes show up.
- Keep keyword case consistent across a codebase.
Limitations
- The formatter does not check whether the SQL is valid or will run.
- Procedural code with unusual syntax may not format perfectly.
Privacy
Queries are formatted in your browser. Table names, customer data in WHERE clauses and production queries are not uploaded.
Frequently asked questions
Does it change what the query does?
No. Only spaces, line breaks and keyword case change.
Which databases are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), SQLite, Oracle PL/SQL, BigQuery and more.
Is my query uploaded?
No. Formatting runs in your browser, so it is safe for production queries.
Can it minify SQL?
No. It is designed to make SQL readable; for compact output, remove line breaks with a text tool.
Can it format several statements?
Yes. Statements separated by semicolons are formatted one after another with a blank line between them.