How to format SQL
- Paste your query into the SQL box, or drop a
.sqlfile on it. - Choose your Dialect, so that database specific syntax is understood.
- Pick the keyword case and indent. The formatted query appears on the right. Select Copy or Download to keep it.
The result updates as you type, so you can adjust the options and watch the layout change.
What formatting does
SQL ignores most white space, which means queries are often written on one long line or squeezed together by tools that generate them. The formatter puts each clause on its own line, indents column lists and conditions, and aligns joins and sub-queries so you can see the structure at a glance. It can also make keywords upper case, the common convention, or lower case if your team prefers.
Because formatting only touches whitespace and keyword case, it never changes the result of the query. The formatter reads the query as tokens, so quoted strings and identifiers are left exactly as they are.
Choosing a dialect
Databases add their own syntax. PostgreSQL has :: casts and $1 parameters, MySQL uses backticks for names, SQL Server uses square brackets and TOP, and BigQuery has arrays and structs. If your query uses these, pick the matching dialect. If you are unsure, standard SQL works for most plain queries.
Tips
- Format a query before you share it in a code review or ticket. People read structured SQL much faster.
- Use upper case keywords and lower case names so that the two stand apart.
- When a query returns the wrong rows, formatting often shows the problem, such as an
ORthat should be inside brackets. - Keep long queries in a file and use version control, so changes are easy to compare.
- Searching logs for table names? The regex tester can help build the pattern, and the cron expression explainer can check the schedule that runs your report.
Your SQL stays in your browser. Nothing is sent to a server.