SQL Formatter
Turn a wall of SQL into a readable query, or squeeze it onto one line.
How to use the SQL Formatter
- Paste your SQL, or open a .sql file.
- Choose the dialect so its special syntax is understood.
- Pick uppercase or lowercase keywords and your indentation.
- Copy the formatted query or save it as a .sql file.
Examples
About this tool
SQL copied from logs, ORMs and old scripts often arrives as a single endless line, which makes joins, conditions and subqueries hard to follow. This formatter puts each clause on its own line, indents nested queries and lists of columns, and lines up joins and conditions so the structure of the query is obvious at a glance.
Dialects matter. PostgreSQL has casts like ::date and dollar-quoted strings, SQL Server uses square brackets around names, MySQL uses backticks, and BigQuery and Snowflake add their own functions. Choosing the right dialect lets the formatter recognise those correctly instead of mangling them. The formatting itself is handled by the open-source sql-formatter library.
Minify mode does the opposite: it removes comments and squeezes the query onto one line while leaving everything inside quotes alone, so a string such as "-- not a comment" is kept intact. That is handy for embedding a query in code, a config file or a URL.
Frequently asked questions
Does formatting change what my query does?
No. Only spaces, line breaks and, if you choose, the case of keywords change. Table names, column names and string values are left exactly as you wrote them.
Why did I get an error?
Usually because of an unclosed quote or bracket, or syntax that belongs to another dialect. Check the line mentioned in the message and try selecting the database you actually use.
Should SQL keywords be uppercase?
It is a convention, not a rule. Uppercase keywords make the structure stand out from table and column names, which is why many teams prefer it, but databases accept either.
Is my SQL sent to a server?
No. Queries are formatted on this page, so table names, customer data in WHERE clauses and anything else stay on your computer.