SQL formatter
Paste a query that arrived on one line and get it back indented clause by clause, in the dialect your database speaks.
How to use it
- Paste one or more SQL statements, or open a
.sqlfile. - Pick your database’s dialect so its own keywords and quoting are understood.
- Choose upper-case, lower-case or unchanged keywords, and the indentation.
- Copy the formatted SQL or download it as
query.sql.
What formatting changes, and what it does not
Formatting moves each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) to its own line, puts one column per line, indents subqueries and conditions, and sets the case of keywords. Identifiers, string literals and comments are kept exactly as written, so the query does the same thing before and after.
Why the dialect matters
Databases disagree on details: backticks in MySQL, square brackets in SQL Server, :: casts in PostgreSQL, QUALIFY in Snowflake and BigQuery. Choosing the dialect lets the formatter read these as the database does. If a query fails to format, the message names the first token it could not read; trying the exact dialect usually fixes it.
Related tools
Questions people ask
Is my SQL sent anywhere?
No. It is formatted in your browser, so queries with table names or data never leave your device.
Does it check that my SQL is correct?
No. It formats the text; it does not connect to a database or check that tables and columns exist. Some syntax errors stop the formatter, and the message points to them.
Can it format several statements at once?
Yes. Statements separated by semicolons are formatted one after another, with a blank line between them.
Which library does the formatting?
The open-source sql-formatter library, running in your browser.