Developer tool
SQL Formatter
Format and beautify SQL for MySQL, PostgreSQL, SQL Server, Oracle, SQLite, BigQuery and more. Set keyword case and indent, or minify safely in your browser.
Free, no sign-up. Runs in your browser; nothing is uploaded.
SQL input
Options
Result
How to use the sql formatter
Make a long query readable
Paste your SQL, pick the dialect that matches your database, and the formatted query appears below. Use Sample query to see what the tool does with a typical report query and an update statement.
Choose the options
- Dialect tells the formatter how to read quotes, operators and keywords. If you are unsure, start with Standard SQL, then switch to PostgreSQL, MySQL or SQL Server and compare.
- Keyword case sets
selecttoSELECT(upper), keeps it lowercase, or leaves your text as typed. Upper case for keywords is the most common team convention because it separates commands from table and column names at a glance. - Indent can be 2 spaces, 4 spaces or a tab. Match your repository's style so diffs stay small.
- Lines between queries adds blank lines between statements separated by semicolons.
Minify for compact strings
Switch to Minify when you need SQL on one line, for example inside a log message, a configuration value or a code string. Minify removes -- line comments and block comments, collapses whitespace, and never alters quoted text. Hints such as /*+ ... */ and MySQL's /*! ... */ are kept, since removing them can change execution. If your strings use backslash escapes, as in MySQL, tick the backslash option.
Fixing errors
The formatter reports the first thing it cannot read. Typical causes:
- An unclosed single quote or parenthesis.
- The wrong dialect, such as T-SQL brackets under MySQL.
- Template placeholders like
{{ table }}or$1mixed into the query.
Good habits
- Format a query before reviewing it. Long joins and nested subqueries become easy to scan.
- Keep one condition per line in WHERE clauses so changes show clearly in a diff.
- Never paste real credentials or customer data into any tool you do not control. This one runs locally, but the habit is worth keeping.
Frequently asked questions
Why does the dialect matter?
Dialects differ in quoting, operators and keywords. PostgreSQL uses double-quoted names and :: casts, MySQL uses backticks, SQL Server uses square brackets and TOP. Choosing the right one lets the formatter tokenise your query correctly.
Will formatting change what my query does?
No. Formatting only changes whitespace and, if you pick it, the letter case of keywords. String literals and names keep their exact text. Check the output before you run it on production data.
What does Minify remove?
It strips comments and collapses whitespace to single spaces. Text inside quotes is never touched, and optimizer hints and MySQL executable comments are kept because they change how a query runs.
Why do I get an error for valid SQL?
Usually the dialect is wrong, or the statement uses syntax the formatter does not know yet, such as a vendor-specific extension. Try Standard SQL or a closer dialect, and check for unbalanced quotes or brackets.
Is my query sent to a server?
No. The formatter library is loaded into your browser the first time you use it, and your SQL never leaves your device.