SQL Formatter
Beautify SQL for PostgreSQL, MySQL, SQL Server, Oracle, BigQuery and more — strings and comments untouched.
SQL
Formatted
The formatted SQL appears here. Strings, comments and quoted names are kept exactly as written.
Runs in your browser — nothing you enter leaves this device.
About this tool
What it does
Long queries copied from logs, ORMs or reporting tools usually arrive as a single unreadable line. This formatter lays SQL out the way people read it: each clause — SELECT, FROM, JOIN, WHERE, GROUP BY — on its own line, columns and conditions indented beneath it, and statements separated. It reads the query with the grammar of the dialect you choose, so it understands backtick, bracket and double-quoted names, dollar-quoted strings and each database’s parameter style, and it never changes text inside strings or comments. Formatting only changes whitespace and, if you ask, the case of keywords — the query does exactly the same thing afterwards.
How to use it
- Choose your database’s dialect. Standard SQL works for most simple queries.
- Pick keyword case — UPPER, lower, or as you typed it — and 2 spaces, 4 spaces or tabs.
- Paste a query or a whole script. The formatted version appears as you type.
- If a query can’t be parsed, the message says where. A more specific dialect often fixes it.
- Copy the result.
Limits and your data
- It formats SQL; it doesn’t check that a query is valid for your schema, or run it. A query can format cleanly and still fail on the database.
- Stored procedure bodies and vendor-specific procedural code (complex PL/SQL or T-SQL blocks) are formatted line by line and may not be laid out as neatly as plain queries.
- Templating syntax such as {{ jinja }} or ${variables} inside SQL may not parse; replace it with a placeholder first.
- Input is limited to 1 MB.
- Formatting happens in your browser with the open-source sql-formatter library. Queries — which can include table names, customer data in literals and business logic — are never sent anywhere or run against any database.
Questions
Will formatting change what my query does?
No. Only spaces, line breaks and — if you choose — keyword capitals change. String literals, quoted identifiers and comments are copied exactly, and SQL keywords aren’t case-sensitive.
Why does it say it couldn’t parse my query?
Usually because the query uses syntax from a specific database, such as PostgreSQL’s :: casts, MySQL backticks or SQL Server square brackets, while the dialect is set to Standard SQL. Choose your database, and check for an unclosed bracket or quote near the position shown.
Upper-case or lower-case keywords?
Either works. Upper-case keywords make the structure stand out and are traditional; many modern style guides use lower case. The important thing is that a codebase is consistent.
Can I format a whole migration file?
Yes. Multiple statements are formatted and separated by a blank line, and the footer shows how many statements it found.