About this tool
SQL written in a hurry often ends up as one long line that is hard to read, review or debug. This formatter breaks a query into clauses, puts SELECT, FROM, WHERE and ORDER BY on their own lines, indents column lists and conditions, and lets you choose the dialect so vendor-specific syntax is understood.
Formatting runs in your browser with the open-source sql-formatter library, so queries that mention real table names never leave the page. You can pick keyword case and indent width, collapse a query back to a single line with comments removed, and download the result as query.sql. Syntax problems are reported instead of producing a half-formatted result.
How to use the SQL Formatter
- 1Paste or type a SQL query into the input editor, or click Sample.
- 2Pick the dialect that matches your database, such as PostgreSQL, MySQL or SQL Server.
- 3Choose UPPER, lower or preserved keyword case and an indent of two spaces, four spaces or tabs.
- 4Check the formatted query in the output editor, which updates as you type.
- 5Click Minify for a single-line version, then copy it or download query.sql.
Features
Eight SQL dialects
Standard SQL, PostgreSQL, MySQL, SQLite, SQL Server, BigQuery, MariaDB and Oracle PL/SQL each get their own quoting and keyword rules.
Keyword case control
Write keywords in uppercase or lowercase, or leave them exactly as they were typed.
Choice of indent
Indent nested clauses with two spaces, four spaces or tab characters to match the style of your codebase.
Safe minify
Collapse a query to one line, removing line and block comments while leaving quoted strings and identifiers untouched.
Readable parse errors
When a query cannot be parsed, the position of the problem is shown and the last good output stays on screen.
Frequently asked questions
Which SQL dialects are supported?
Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), BigQuery and Oracle PL/SQL. Pick the one that matches your database so quoting and vendor keywords are handled correctly.
Does formatting change what my query does?
No. Only whitespace, line breaks and the letter case of keywords change. Table names, column names and string values keep their original spelling.
What does Minify remove?
It removes comments that start with two dashes, removes block comments, and squeezes runs of whitespace into one space. Text inside single quotes, double quotes and backticks is left exactly as written.
Why do I get a parse error?
The formatter reads the query before laying it out, so an unclosed bracket, an unfinished string or an unsupported statement stops it. Check the position in the message, or try a different dialect.
Is my SQL query sent anywhere while it is formatted?
No. Formatting and minifying run in your browser tab, and the query is not stored once you close the page.