SQL Formatter and Beautifier
Paste a SQL query to make it readable: each main clause, such as SELECT, FROM, WHERE, JOIN and ORDER BY, starts a new line, column lists and AND/OR conditions are indented, and subqueries are nested. You can uppercase keywords or leave them as written, or minify the query onto one line. String literals, quoted names and comments are never changed, and queries stay in your browser.
SQL Formatter and Beautifier
Only whitespace and the case of SQL keywords change. String literals, quoted names (`name` and "name") and comments are copied exactly, and table or column names keep their case. Quotes follow MySQL rules, where a backslash escapes the next character. The formatter does not check that the SQL is valid.
Runs in your browser. Nothing you enter is uploaded or saved.
How to use this tool
- Paste your SQL. Paste one query or several separated by semicolons.
- Pick options. Choose the indent size and whether to uppercase keywords.
- Format or minify. Press Format for a readable layout or Minify to collapse it onto as few lines as possible.
- Copy the result. Copy the query into your code, migration or documentation.
What changes and what does not
Only whitespace and the case of SQL keywords change. Text in quotes ('text'), quoted names (`name` or "name"), comments and numbers are copied exactly, and table and column names keep their case, which matters on servers where table names are case-sensitive.
Why format SQL?
One clause per line makes long queries easier to read, review and compare in version control. It is much easier to spot a missing join condition or a wrong AND/OR grouping when each condition sits on its own line.
Dialects
The formatter is built around MySQL and MariaDB and handles common PostgreSQL and SQLite syntax too. Quotes follow MySQL rules, where a backslash escapes the next character, and # starts a comment. It does not check that a query is valid.
Frequently asked questions
Should SQL keywords be uppercase?
It is a style convention, not a rule; SQL keywords are not case-sensitive. Uppercase keywords make it easier to tell them apart from table and column names.
Is it safe to paste queries containing data?
Yes. Formatting runs in your browser and nothing is uploaded or stored. Still avoid sharing real customer data in queries you send to others.
Why are line comments kept on their own line when minifying?
A -- or # comment runs to the end of the line, so joining the next line onto it would turn your code into part of the comment.