About the SQL Formatter tool
Queries copied from application logs, ORMs and BI tools usually come out as a single long line that is hard to review. This SQL formatter rewrites them with each clause on its own line, columns and conditions indented underneath, and consistent keyword casing, so joins, filters and groupings are easy to follow.
Formatting is powered by the sql-formatter library, which understands the syntax differences between databases. Choose the dialect that matches your system: Standard SQL, MySQL, PostgreSQL, SQL Server (T-SQL), SQLite, BigQuery or Oracle PL/SQL. That way dialect-specific features such as backtick identifiers, :: casts or square-bracket names are recognised correctly. You can make keywords UPPERCASE, lowercase or keep them as typed, and indent with 2 spaces, 4 spaces or tabs. Several statements separated by semicolons are formatted with a blank line between them. If the formatter cannot parse part of a query, it reports the line and column where it got stuck.
Your SQL is formatted in the browser and never sent to a server, so queries that reveal table names or customer data stay private.
How to use SQL Formatter
- Paste SQL into the “SQL input” box, open a .sql file with “Open file”, or click “Load sample”.
- Choose the Dialect that matches your database.
- Set the “Keyword case” and the Indent.
- Read the formatted SQL on the right; parse errors show the line and column.
- Click “Copy” or “Download” to save the formatted .sql file.
Features
Seven SQL dialects
Standard SQL, MySQL, PostgreSQL, T-SQL, SQLite, BigQuery and PL/SQL are supported.
Keyword casing
Convert keywords to UPPERCASE or lowercase, or keep them as written.
Indent control
Use 2 spaces, 4 spaces or tabs for nested clauses.
Multiple statements
Scripts with several queries are formatted with clear separation.
Located errors
Unparseable input is reported with the line and column of the problem.
When to use it
- Make a slow query from a log file readable before analysing it.
- Format SQL generated by an ORM such as Hibernate, Sequelize or Django.
- Standardise query style before committing migrations.
- Prepare readable SQL for code reviews, tickets and documentation.
- Learn how a complex query is structured by seeing each clause separately.
Frequently asked questions
Does the formatter change what my query does?
No. Only whitespace, line breaks and keyword casing change. Table names, values and logic stay the same.
Why do I get a parse error?
The query may use syntax from a different database than the selected dialect, or contain a typo such as an unclosed bracket. Try the correct dialect and check the reported line and column.
Does it validate my SQL against my database?
No. It checks only that the query can be tokenised and parsed for formatting; it does not know your tables or run anything.
Can I format stored procedures?
Simple procedures usually format well with the matching dialect, but very complex procedural code may not be laid out perfectly.
Is my SQL uploaded?
No. Formatting runs entirely in your browser.
Which dialect should I pick if I am not sure?
Start with Standard SQL. If you get a parse error on syntax like backticks, :: casts or square brackets, switch to MySQL, PostgreSQL or SQL Server respectively.