SQL Formatter Online Free
Paste any SQL query and format it instantly — keywords uppercased, clauses on their own lines, consistent indentation. Supports MySQL, PostgreSQL, SQLite, T-SQL, BigQuery and more.
SQL Formatter
How to Format a SQL Query
- 1Paste your SQL query or script into the input box.
- 2Choose the correct SQL dialect for your database and your preferred indent size.
- 3Click Format SQL. Keywords are capitalised and the query is indented with each clause on its own line.
- 4Click Copy to copy the result to your clipboard.
Why Format SQL?
Unformatted SQL — especially queries generated by ORMs, exported from databases, or written in a hurry — can be a single dense line of text that is nearly impossible to read or debug. A formatted query makes the structure immediately obvious: you can see which columns are being selected, which tables are joined, and which conditions apply at a glance.
Consistent formatting also helps when committing SQL migrations, stored procedures, or view definitions to version control. A formatted SQL file produces clean, meaningful diffs — a WHERE clause change is one line, not a needle in a haystack of whitespace.
SQL Formatting Tips
Choose the Right Dialect
MySQL uses backtick quoting, PostgreSQL uses double quotes, T-SQL uses square brackets. Selecting the correct dialect ensures identifiers and syntax extensions are handled correctly.
Format Before Committing
Always format SQL migration files and stored procedures before committing to version control. Consistent formatting means git blame and diffs show real logical changes, not whitespace noise.
Paste ORM-Generated SQL
Copy the raw SQL logged by your ORM (e.g., from Django, Rails, or SQLAlchemy debug output) and paste it here to read it. Long parameterised queries become readable in seconds.
Multiple Statements Welcome
Paste an entire SQL script — CREATE TABLE, INSERT, SELECT — all separated by semicolons. The formatter handles each statement individually with a blank line between them.
Frequently Asked Questions
What SQL dialects are supported?
The formatter supports Standard SQL, MySQL, PostgreSQL, SQLite, T-SQL (Microsoft SQL Server), PL/SQL (Oracle), BigQuery, and MariaDB. Select the dialect matching your database from the dropdown — different dialects have slightly different keyword sets, quoting rules, and syntax extensions.
What does the formatter change?
The formatter adds consistent indentation, puts each clause (SELECT, FROM, WHERE, JOIN, ORDER BY, GROUP BY) on its own line, capitalises all SQL keywords (SELECT, FROM, WHERE, etc.), and adds line breaks between multiple queries. It does not validate whether the query will execute correctly — it only improves visual structure.
Does the formatter validate my SQL?
The tool uses a lenient parser — it formats without strict validation. Minor issues like unknown function names or dialect-specific extensions usually format without error. If the formatter cannot parse the input (for example, completely invalid syntax), it will display an error. For strict validation, you need to run the query against an actual database.
Is my SQL sent to a server?
No. The sql-formatter library runs entirely in your browser. Your queries are never transmitted over the network and are never stored anywhere. The tool works correctly offline once the page has loaded.
Why does my query look different from what I expected?
sql-formatter applies opinionated formatting rules: keywords are always uppercased, each clause starts on a new line, and subqueries are indented. These rules are designed for readability and match common SQL style guides. If the output differs from your team's style, you may want to adjust the indent setting or clean up minor differences manually.
Can I format multiple SQL statements at once?
Yes. Paste multiple queries separated by semicolons and the formatter handles each one with a blank line between them. This works for SQL scripts with CREATE TABLE, INSERT, UPDATE, SELECT, and DROP statements mixed together.