About this tool
SQL Formatter lays out a query so its structure is obvious: each clause on its own line, joins and conditions indented beneath it, subqueries and CTEs (the named “WITH” blocks at the top of a query) nested clearly, and keywords in the case you prefer. The result is coloured, so keywords, functions, text values, numbers and comments stand apart.
It understands 20 dialects, including MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark and DB2. Picking the right one matters: it decides whether [Order Details] is a name or an error, whether # starts a comment, and how parameters like :id, @id or $1 are read.
It is handy for analysts tidying a query before sharing it, developers reading SQL pulled from logs or an ORM, and anyone pasting a query into documentation or a code review. One line mode does the opposite, squeezing a formatted query into a single line for a config file or a test. Your queries never leave your browser, which matters when they contain table names, customer IDs or other internal details.
How to use SQL Formatter
- Paste a query into “Your SQL”, press “Open file” to load a .sql file, or press Example to try one.
- Choose your database from the Dialect list.
- Pick the keyword case (UPPER, lower or As typed) and the indent. Open “More options” for the layout, where AND and OR go, blank lines between queries and dense operators.
- If the status box turns red, read the plain-English message and press “Go to the problem” to jump to that spot.
- Press Copy, or “Download .sql” to save the result. Switch to “One line” when you need the query squeezed back onto a single line.
Pasting “select u.id, count(o.id) orders from users u left join orders o on o.user_id = u.id group by u.id” with PostgreSQL and UPPER gives SELECT, FROM, LEFT JOIN and GROUP BY each starting a line, the columns indented beneath SELECT, and COUNT in capitals.
Features
- 20 dialects: Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), SQLite, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, DB2, DB2 for i, DuckDB, ClickHouse, Hive, Trino, TiDB, SingleStore and Couchbase N1QL.
- Keyword case UPPER, lower or exactly as typed, optionally applied to function names and data types as well.
- Indent with 2 spaces, 4 spaces or tabs, in a standard or tabular layout.
- AND and OR at the start or the end of lines, 0 to 3 blank lines between queries, dense operators, and a semicolon on its own line if you like.
- One line mode that keeps every quoted value and name exactly as written, with comments removed or kept as /* … */.
- Colour highlighting of keywords, functions, data types, text, numbers, comments, quoted names and parameters, readable in dark and light themes.
- Plain-English problems with the line, column and the line itself marked, plus advice such as “choose SQL Server for [bracket] names”.
- Line numbers, drag-and-drop for .sql files, and your settings remembered in this browser.
Tips and good to know
- If a valid query shows a problem, the dialect is the usual cause. Backtick names suit MySQL or BigQuery, square brackets need SQL Server or SQLite, and $$ blocks need PostgreSQL.
- Formatting only changes spaces, line breaks and the case of keywords. Table names, column names and quoted values stay exactly as you typed them.
- Stored procedures with their own control flow (loops, IF blocks, custom delimiters) are formatted as best the dialect allows, but very procedural code may still need a manual touch.
- One line mode turns “-- comments” into /* comments */ when you keep them, because a double-dash comment would otherwise swallow the rest of the line.
Frequently asked questions
Are my queries uploaded anywhere?
No. Formatting, colouring and one line mode all happen in your browser. The formatter is downloaded once when you first use it; your SQL itself is never sent to AroraTools or anyone else.
Is it free? Is there a limit on query size?
It is free with no sign-up and no daily cap. Scripts of thousands of lines work, though a very long script takes a moment to format. Results over about 300 KB are shown without colours to keep the page quick.
Does it work on a phone or offline?
Yes. The two boxes stack on a phone screen and the controls are large enough to tap. Once the formatter has loaded, it keeps working without a connection until you close the tab.
Which dialect should I choose?
Choose the database the query will run on. If you are not sure, Standard SQL handles most everyday SELECT, INSERT, UPDATE and DELETE statements. Switch dialect if it reports a problem with names in brackets, backticks, # comments or parameters.
Will formatting change what my query does?
No. Only whitespace and the letter case of SQL keywords change, and keywords are not case-sensitive in any of these databases. Names in quotes, text values and numbers are left exactly as they were.
Can it check that my SQL is correct?
Partly. It spots broken structure, such as an unclosed bracket or quote, and says where. It does not know your tables, so a misspelt column name or a missing table will still format happily.
Page last reviewed
