SQL Formatter
A tool that automatically formats messy SQL using the sql-formatter library. It supports choosing a dialect (Standard SQL, MySQL, PostgreSQL, and more), converting keyword case, and minifying to a single line.
How to use
- Paste the SQL you want to format into the input area on the left.
- On the "Format" tab, choose a SQL dialect (Standard, MySQL, PostgreSQL, etc.) and whether reserved words should be uppercase, lowercase, or left as-is.
- The right side shows the indented, formatted SQL in real time.
- To collapse it back to a single line, switch to the "Minify" tab, which generates a single-line SQL statement with comments removed.
About this tool
This tool automatically reformats SQL with broken line breaks and indentation into a readable structure. It makes it easy to grasp the structure at a glance when reviewing a single-line SQL statement from a log, or SQL generated by another tool.
Formatting is powered by the popular open-source library "sql-formatter", supporting Standard SQL as well as dialect-specific syntax for MySQL, PostgreSQL, SQLite, MariaDB, Transact-SQL (SQL Server), and BigQuery.
It also offers an option to normalize the case of reserved words (SELECT, FROM, WHERE, etc.), plus a feature to compress SQL down to a single line — useful for enforcing a coding convention or producing compact SQL for logging.
Frequently asked questions
I'm not sure which SQL dialect to choose.
Choose the one matching the database you're using. If you're not using syntax specific to a particular dialect, "Standard SQL" will usually format it fine.
The formatted syntax sometimes differs slightly from my actual environment.
This tool parses SQL syntax to adjust indentation — it doesn't actually execute or validate the SQL. Some dialect-specific functions or syntax may not format exactly as intended.
What happens to comments when minifying?
Both line comments starting with "--" and block comments using "/* */" are removed, and the remaining whitespace and line breaks are collapsed into single spaces to produce a single-line SQL statement.
Is my input SQL sent to a server?
No. Formatting and minifying SQL both run entirely with JavaScript in your browser.