How to use the SQL Formatter
- 1
Paste a query into the Input pane, drop a .sql file onto it, or press Sample. The formatted SQL appears on the right as you type.
- 2
Pick your database from the Dialect menu so its keywords, operators and quoting rules are recognised.
- 3
Choose keyword case (UPPERCASE, lowercase or preserve) and indentation of 2 spaces, 4 spaces or tabs.
- 4
Switch to Minify to collapse a query onto one line for logs, code strings or a URL. Comments are removed and string literals are left untouched.
- 5
Press Copy, or Download to save the result as a .sql file.
Features
- Formats SELECT, INSERT, UPDATE, DELETE, CTEs, joins, subqueries, window functions and DDL
- Thirteen dialects including MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake and Spark
- Keyword case control and 2 space, 4 space or tab indentation
- Several statements in one input, separated by a blank line in the output
- Minify mode that strips comments and whitespace but never touches quoted strings or identifiers
- Parse errors reported with the line and column, underlined in the editor
- Formatting starts as you type, with no submit button
- Runs entirely in your browser; queries are never uploaded
Readable queries
A query that has grown over months of edits, or one copied from a log on a single line, is hard to review. Formatting puts every clause on its own line, indents joins and subqueries under the statement they belong to, and lines up column lists, so you can see the shape of the query at a glance and spot the missing join condition or the filter in the wrong place.
The formatter understands the grammar of each dialect rather than just breaking lines at keywords. Common table expressions, window functions with PARTITION BY and ORDER BY, CASE expressions and nested subqueries all get consistent indentation, and several statements in one paste are formatted one after another.
Consistent style for a team
Formatting everyone’s SQL the same way removes noise from code review. With a fixed keyword case and indentation, a diff shows the change to the logic rather than someone’s personal spacing. If your repository stores migrations or analytics queries as .sql files, format them here before committing, or use the same settings in your editor’s SQL formatter.
Related tasks
To format application code alongside your queries, open the full Code Formatter, which detects the language automatically. For query results exported as JSON, the JSON to CSV converter turns them into a spreadsheet.
Frequently asked questions
Which SQL dialects are supported?
Will formatting change what my query does?
Why do some people write SQL keywords in uppercase?
What does Minify do to comments?
Why does formatting fail on my query?
Is my SQL sent to a server?
Last updated .