SQL Formatter
Format and indent SQL queries for PostgreSQL, MySQL, SQL Server, Oracle, BigQuery and more
About SQL Formatter
Reformats SQL so each clause sits on its own line with consistent indentation and keyword case. Works for the common dialects: standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery and Snowflake.
Paste your query, choose the dialect, indent and keyword case, then press Format. If the query has a syntax the formatter cannot read, you get the message and the original text is left alone.
Formatting changes only whitespace and keyword case, never table names, strings or values. It does not check that the query is valid for your database, so run it there before relying on it.
- Does formatting change what my query does?
- No. Only spacing, line breaks, indentation and, if you choose, the capitalisation of keywords change. Names, strings, numbers and operators stay the same.
- Which SQL dialects are supported?
- Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery and Snowflake. Choosing the right one matters for dialect-specific quoting and functions.
- Why does it say it could not format my query?
- The formatter reads the statement before laying it out and stops if it meets something it does not recognise, such as an unclosed quote or syntax from another dialect. Try a different dialect, or check the query near the position in the message.
- Does it check that my SQL is valid?
- No. It reads the structure well enough to indent it but does not know your tables or whether the database would accept it. Run the query in your own database to validate it.
- Is my query uploaded?
- No. It is formatted in your browser and is not sent or stored, which matters if it contains internal table or column names.
How to use SQL Formatter
Paste your query into the SQL box, pick the dialect (standard, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery or Snowflake), the indent (2 spaces, 4 spaces or a tab) and the keyword case (upper, lower or as typed), then press Format. Copy the formatted query from the right-hand box.
When to use it
Use it to make a long one-line query readable before reviewing it, pasting it into a ticket or code review, or committing it to a repository. It also helps when you inherit generated SQL from an ORM or a report tool and need to see its structure.
When not to use it
It does not run, validate or optimise the query, so it cannot tell you whether a table exists or whether the statement is correct for your database. Choosing the wrong dialect can lead to an error for syntax that dialect does not know. Very unusual vendor extensions may not be understood.
Tips for best results
Pick the dialect that matches your database; it affects things like quoting with backticks, double quotes or square brackets. Use 'As typed' for keyword case if your team keeps its own style. Always test the formatted query in your database before relying on it.
Limitations
Only whitespace, line breaks and keyword case change. If the formatter cannot read the statement it shows its message and leaves the output empty rather than guess. Comments are kept. Several statements separated by semicolons are formatted one after another with a blank line between them.
Privacy
Formatting runs in your browser with a bundled library. The query, which may contain table and column names, is not uploaded or saved anywhere.
More from Security & Developer: