Format and Minify SQL Queries
Format SQL, change keyword case, or make a compact version; strings, quoted names, and comments stay unchanged.
Use this tool in your browser without installing software.
About this tool
This page reads SQL token by token and lays it out again. Each clause — SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, JOIN, UNION, VALUES, SET and RETURNING — starts its own line; AND and OR conditions hang one level under WHERE; a subquery in parentheses gets its own indented block; and each VALUES row sits on its own line. A line longer than 100 characters is wrapped at its top-level commas so you do not have to scroll sideways. Strings, quoted names and comments are never rewritten; only the position of a comment may move. With Minify checked the extra whitespace goes away, but comments stay, and a line comment keeps a newline after it — otherwise the rest of the query would become part of the comment. The dialect decides what is accepted: in MySQL a double quote is a string and # starts a comment, in PostgreSQL a double quote is an identifier and a single quote is a string, and SQLite accepts all three quoting styles. The tool checks structure — matching parentheses, closed quotes and closed comments — not the meaning of the statement; running the query is the database’s job. Nothing is sent anywhere.
How to use it
- 1
Paste a query into the input box, or pick a .sql file with Open. The result appears as you type.
- 2
Choose the dialect at the top, then adjust indentation or keyword case if you like. Minify removes unnecessary whitespace while keeping comments and required line breaks.
- 3
Copy the result or download it. If there is a structural problem, the line, the column and that source line with a ^ marker appear under the boxes.
If the file will not open
- It says a parenthesis is never closed.
The line and column point at the opening parenthesis, and the source line is marked with ^. Usually a parenthesis is missing in a condition or a column list, or two were opened and only one closed.
- It says a string is not closed.
A single quote was left open. In SQL a quote inside a string is written twice: 'it''s' is correct. If the text came from a language that escapes with a backslash, use the doubled quote in PostgreSQL mode.
- A backtick is rejected.
In PostgreSQL mode a backtick is not valid, and in SQLite it is allowed for names. If the file came from MySQL, press MySQL, or change the backticks to double quotes.
- Statements inside BEGIN … END got scrambled.
This tool reads every ; as the end of a statement and does not understand a procedural body. The output is still valid, but for long bodies you may prefer to fix the indentation by hand or format only the outer statement here.
Frequently asked questions
Do you check whether the query is correct?
No. This tool only looks at structure: matching parentheses, closed quotes and closed comments. Whether a table exists, a column name is right or the types line up is the database’s job. A query can leave this page well-formed and still fail in MySQL or PostgreSQL.
Why did the AND inside BETWEEN stay on the same line?
Because that AND belongs to BETWEEN, it does not separate two conditions. Moving it to a new line would make the condition harder to read. The same rule applies to AND and OR inside CASE, so the expression stays in one piece.
Why are some lines still long?
Lines are only wrapped at top-level commas, up to 100 characters. If a single column or string literal is longer than that on its own, there is nowhere safe to break it and it stays as written. A string is never split, because splitting it would change its value.
What changes between MySQL and PostgreSQL?
How the text is read. In MySQL a double quote is a string and # starts a comment, so SELECT "x" is text. In PostgreSQL the same double quote is an identifier and # is an operator. In SQLite double quotes, backticks and brackets all name a column. If you paste MySQL text in PostgreSQL mode, a backtick is rejected, which tells you to switch modes.
What happens to comments when I minify?
They are kept. A block comment stays where it is, and a line comment keeps a newline after it; without that newline the rest of the query would become part of the comment and change its meaning. If you do not want comments, remove them before minifying.
Does it format the body of a stored procedure or trigger?
Carefully. This tool does not treat a BEGIN … END body as a procedural block; every ; is read as the end of a statement. The result is still valid, but statements inside the body may end up on separate lines without the indentation you wanted. For long bodies, give the output a quick read. If the body is written as a dollar-quoted literal ($$ … $$ or $tag$ … $tag$), it counts as a string and is left completely untouched.