SELECT, FROM, WHERE and the rest start their own lines, columns are listed one per line, and nested brackets are indented. Choose 2 spaces, 4 spaces or tabs.
Developer
SQL Formatter
Paste a long, tangled query and get it back one clause to a line, with keywords in the case you choose. Pick your database so its syntax is read correctly.
How to use this tool
Paste one or more SQL queries, drop a .sql file, or press Sample.
Choose your Dialect, such as PostgreSQL, MySQL or SQL Server, so its syntax is read correctly. Set Keywords to UPPERCASE, lowercase or As written, choose the Indent, and decide whether AND / OR start the line. Choose One line to squeeze the query onto a single line instead.
An unfinished string, comment or bracket is reported with its position. When the result looks right, press Copy result or Download.
How to use this tool
Paste one or more SQL queries, drop a .sql file, or press Sample.
Choose your Dialect, such as PostgreSQL, MySQL or SQL Server, so its syntax is read correctly. Set Keywords to UPPERCASE, lowercase or As written, choose the Indent, and decide whether AND / OR start the line. Choose One line to squeeze the query onto a single line instead.
An unfinished string, comment or bracket is reported with its position. When the result looks right, press Copy result or Download.
Paste a query, or load the sample, to see it laid out one clause to a line.
Queries you can read at a glance.
A one-line query with six joins is hard to review. This lays it out with each clause on its own line, joins and conditions indented, so mistakes stand out.
PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery, Snowflake and others each have their own quoting and functions. Choose yours so they are read as written.
Text in quotes, comments and dollar-quoted blocks is left exactly as you wrote it. An unfinished string or comment is reported instead of being guessed at.
Frequently asked questions
Does formatting change what my query does?
No. Only spaces and line breaks change, and optionally the case of keywords. Strings, names and comments are left as they are, so the query runs the same.
Why do I get an error for a query that runs on my database?
Most likely the dialect. Each database has syntax the others lack, so choose yours. If it still fails, the message gives the line and column of the first thing that could not be read.
What does One line do?
It removes comments and squeezes spaces and line breaks into single spaces, giving a compact query to paste into code. Text inside quotes is left untouched.
Can I format several queries at once?
Yes. Separate them with semicolons and each is formatted in turn, with a blank line between them.
Should keywords be uppercase?
It is a convention, not a rule. Uppercase keywords make the structure of a query easier to see, but lowercase or As written work just as well. Names of tables and columns are never changed.
