SQL Formatter
Beautify SQL for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery and more. Strings and comments stay untouched.
When you need a SQL formatter
SQL rarely arrives in a readable shape. ORMs log queries as one long line, BI tools export them with random line breaks, and a query copied from a Slack thread loses its indentation. Reading a 400-character SELECT to find a missing join condition is slow and error-prone. This formatter rewrites the layout of the query — one clause per line, indented column lists and conditions, consistent keyword case — without changing what it does.
It is built on the open-source sql-formatter library, which tokenizes the query according to the dialect you pick. That is the important difference from simple search-and-replace formatters: text inside quotes such as 'active -- not a comment' and real comments are recognised as such, so they are never split, uppercased or turned into code.
How to use it
- Pick your database in Dialect. If you are not sure, Standard SQL works for most simple queries.
- Paste one or more statements into SQL input, or press Load example to see a sample.
- Choose Keyword case, Indent and where AND / OR should go. The result updates as you type.
- Use Copy or Download .sql to take the Formatted SQL back to your editor, migration file or pull request.
Worked example
With Dialect = MySQL, Keyword case = UPPERCASE, Indent = 2 spaces and AND / OR at the start of the line, this input:
select id, name from users where status = 'active' and age > 30 order by name;
becomes:
SELECT id, name FROM users WHERE status = 'active' AND age > 30 ORDER BY name;
Each clause keyword starts a line, its contents are indented one level, and every selected column gets its own line — which makes diffs in code review much easier to read when a column is added or removed. The literal 'active' is untouched.
What the options do
- Dialect — controls which keywords, quote styles and placeholders are understood: backtick identifiers in MySQL,
[brackets]in SQL Server,$1parameters and::casts in PostgreSQL,@paramin T-SQL and BigQuery. - Keyword case — UPPERCASE is the most common convention because it separates keywords from table and column names at a glance. Preserve leaves keywords exactly as you typed them. Identifiers are never re-cased.
- Indent — 2 or 4 spaces, or a tab character, to match your editor or style guide.
- AND / OR — "Start of line" puts each logical operator at the beginning of the condition it introduces (easy to comment out a single condition); "End of line" keeps the operator after the previous condition.
Limitations
- It is a formatter, not a validator. A query can be formatted perfectly and still reference a table that does not exist.
- Procedural code (stored procedures, PL/pgSQL function bodies, T-SQL control flow) is formatted on a best-effort basis; complex blocks may keep a layout you would arrange differently by hand.
- If the parser cannot understand part of the input, nothing is output and an error with line and column is shown instead — the tool never returns a half-formatted query.
- Input is limited to 500,000 characters to keep the page responsive. For huge dump files, use a command-line formatter.
Tips and common mistakes
- Parse error on valid SQL? Check the dialect first.
SELECT [x] FROM tfails as MySQL but formats correctly as SQL Server. - Remove secrets before sharing. Formatting happens locally, but once you paste the result into a ticket, any customer data in literals goes with it.
- Format before diffing. Formatting both versions of a query with the same settings removes whitespace noise, so a diff shows only real changes.
- Need INSERT statements from a spreadsheet? Generate them with the CSV to SQL converter, then format them here. For query results exported as JSON, use the JSON formatter.
Frequently Asked Questions
Which SQL dialects does this formatter support?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, SQL Server (T-SQL), Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark SQL, Trino/Presto, DuckDB, IBM Db2 and Hive. Choosing the right dialect matters because quoting, placeholders and keywords differ between databases.
Will the formatter change my string literals or comments?
No. The query is tokenized per dialect before formatting, so text inside quotes, quoted identifiers and -- or /* */ comments is copied through unchanged. Only whitespace and, if you choose, keyword case are changed.
Does it validate SQL syntax?
Only partially. If the formatter cannot parse the input (for example an unclosed string or bracket) it shows a parse error with the line and column. It does not check table names, column names or types — only a database can do that.
Why do I get a parse error for valid SQL?
Usually because the dialect is wrong: square-bracket identifiers like [Order] are T-SQL, backticks are MySQL, and $1 placeholders are PostgreSQL. Switch the Dialect selector to your database and try again.
Can I format several statements at once?
Yes. Paste a whole script; statements separated by semicolons are formatted one after another with a blank line between them.
Is my SQL query sent to a server?
No. The formatting library is downloaded to your browser and runs there. Your queries, including any data inside them, never leave your device.
Related tools
- UUID GeneratorGenerate RFC 4122 compliant UUIDs (v1, v4, v5) in bulk. Export as JSON, CSV, or plain text.
- Lorem Ipsum GeneratorGenerate Lorem Ipsum placeholder text in paragraphs, sentences, or words with optional HTML output.
- QR Code GeneratorGenerate customizable QR codes for URLs, text, emails, WiFi, vCards, and phone numbers.
- QR Code ScannerScan QR codes with your camera or from an image file directly in the browser. Copy the result, open safe links and see the decoded content type.
- Regex TesterTest, debug, and visualize regular expressions against sample text in real time with match highlighting.
- JWT GeneratorGenerate and sign JSON Web Tokens (JWT) with custom header, payload, and secret. Supports HS256, HS384, HS512, RS256 algorithms.
Found a bug or a wrong result? Report it.