Use this free SQL formatter to turn a long, one-line query into clean, readable SQL, or to compress it back into a single line. Paste your query, choose a keyword case and an indentation style, and click Format. Clauses such as SELECT, FROM, and WHERE start on their own lines, subqueries are indented, and the tool warns you about unclosed quotes and brackets. You can copy the result or download it as a .sql file.

Readable SQL is easier to debug, review, and share. Format it before you commit it, and minify it only when size matters.

How to use the SQL formatter

  • Paste your SQL: drop in a query, a stored procedure body, or a whole script with several statements.
  • Choose keyword case: uppercase is the most common style, but you can use lowercase or keep your own.
  • Choose indentation: 2 spaces, 4 spaces, or tabs.
  • Click Format or Minify: Format makes the SQL readable, and Minify removes comments and extra whitespace.
  • Copy or download: copy the result to your clipboard or save it as a .sql file.

What the tool does

ActionBest forWhat you get
FormatReading, reviewing, and debugging queriesOne clause per line with indented lists and subqueries
MinifyEmbedding SQL in code or config filesA single line with comments and extra spaces removed
Keyword caseMatching your team’s style guideUPPERCASE, lowercase, or unchanged keywords
Error checkFinding broken queries earlyA message for unclosed quotes, comments, or brackets

How SQL is formatted

  • Clauses: SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, and UNION each start on a new line.
  • Select lists: each column goes on its own line, so it is easy to add or remove one.
  • Joins and conditions: each JOIN starts a new line, and AND or OR conditions are placed on separate indented lines.
  • Subqueries and CTEs: queries inside brackets are indented one level deeper than the line they belong to.
  • CASE expressions: each WHEN and ELSE branch gets its own line.
  • Strings and comments: text inside quotes is never changed, and comments are kept when you format.

Common SQL errors

  • Unclosed quotes: a string that starts with a single quote must end with one. Use two single quotes to write an apostrophe inside a string.
  • Unbalanced brackets: every opening bracket needs a matching closing one, especially in nested subqueries.
  • Trailing comma before FROM: SELECT a, b, FROM t is invalid because of the extra comma after b.
  • Missing comma between columns: without it, the second column is read as an alias for the first.
  • Double quotes for text: in standard SQL, double quotes mark identifiers, not strings. Use single quotes for text values.
  • Reserved words as names: words like ORDER or GROUP need quoting if you use them as column or table names.
Whether you are reviewing a pull request or debugging a slow report, formatted SQL makes the logic visible, and a quick check catches mistakes before they run.

Worked examples

Format a one-line query

Paste select id,name from users where active=1 and age>18 order by name and click Format with uppercase keywords. The tool puts SELECT, FROM, WHERE, and ORDER BY on separate lines, spaces out the operators, and moves the AND condition to its own line.

Format a subquery

Paste a query with where id in (select user_id from orders). The inner query moves to its own indented block, so you can see where the subquery starts and ends.

Minify a query

Paste a formatted query with comments and click Minify. Comments and line breaks are removed, and the summary shows how many characters you saved.

Frequently asked questions

Is this SQL formatter free to use?

Yes. You can format, minify, copy, and download SQL without creating an account.

Is my SQL uploaded or stored?

No. All processing happens in your browser. Nothing you paste is sent to a server or saved, and clearing the form removes it from the screen.

Does formatting change my query?

No. Only whitespace and the case of SQL keywords change. Table names, column names, string values, and numbers stay exactly as you wrote them.

Which SQL dialects are supported?

The tool follows common SQL syntax and works well for typical MySQL, PostgreSQL, SQL Server, SQLite, and Oracle queries. Dialect-specific features are formatted generically, so very unusual syntax may not be laid out perfectly.

Does it validate my SQL?

It checks for unclosed quotes, unclosed comments, and unbalanced brackets. It cannot check whether your tables and columns exist or whether the query runs on your database, so test it there as well.

What happens to comments?

Formatting keeps your comments. Minify removes them, because a line comment would otherwise swallow the rest of a single-line query.

Share this article