ToolDash
SQL Formatter

SQL Formatter

Paste a SQL query to format it with clean line breaks and indentation, or minify it onto a single line. Choose standard SQL, MySQL or PostgreSQL and set the keyword case, and the result updates as you type.

  • Free, no sign-up
  • Runs in your browser — nothing is uploaded
  • Instant results, no waiting on a server

Paste a query to format it with line breaks, indentation and your choice of keyword case, or minify it onto one line. Pick the dialect that matches your database. Nothing is sent to a server.

Dialect

Keywords

Indent

SQL input
Chars: 0Lines: 0
Formatted SQL
Chars: 0Lines: 1

How to format a SQL query

  1. 1Paste your query into the SQL input panel, or click Upload to open a .sql file. Several statements can go in at once.
  2. 2Pick the dialect that matches your database: Standard SQL, MySQL or PostgreSQL. This decides how quoting, operators and functions are read.
  3. 3Choose the keyword case (UPPER, lower or as typed) and an indent of 2 spaces, 4 spaces or a tab. The formatted SQL appears on the right as you type.
  4. 4Switch to Minify to turn the query into one compact line with comments removed, then copy it or click Save to download query.sql.

Why format SQL?

Queries written by hand, generated by an ORM or copied from a log usually arrive as one long line. A SQL formatter, also called a SQL pretty print tool, breaks it into clauses, so SELECT, FROM, JOIN, WHERE, GROUP BY and ORDER BY each start on their own line, columns and conditions are indented under them, and nested subqueries line up. That makes a query far easier to read, review and debug, and it keeps diffs small when the SQL lives in version control.

The dialect matters because databases differ. MySQL quotes identifiers with backticks and treats a hash as a comment, while PostgreSQL has the :: cast, dollar-quoted strings and its own operators. Choosing the right dialect lets the SQL beautifier read these correctly instead of splitting them apart. Keyword case is a style choice: most teams write keywords in upper case, but you can switch to lower case or leave your own casing alone.

Minifying is the opposite. The SQL minifier collapses whitespace and removes comments so a query fits on one line, which is handy for an environment variable, a log message or a string in code. Text inside quotes is never touched, and optimizer hints such as /*+ INDEX */ are kept.

Formatting is done by the open source sql-formatter library, which loads only on this page, and it runs entirely in your browser. Your queries, table names and data are never sent anywhere.

When developers reach for it

Reading generated queries

Pretty print a query from an ORM, a slow-query log or an error message so you can see its joins and filters.

Code review and version control

Format SQL online before you commit a migration or report, so reviewers see real changes instead of whitespace noise.

Debugging MySQL and PostgreSQL

Use the MySQL formatter or PostgreSQL formatter to lay out a query with backticks, casts or window functions.

Embedding SQL in code

Minify a long query to a single line to put it in a config value, a JSON field or a log entry.

Frequently asked questions

Is my SQL sent to a server?

+

No. The formatter runs in your browser, so queries, table names and any literal values stay on your device.

Which SQL dialects are supported?

+

Standard SQL, MySQL and PostgreSQL. Standard SQL works well for most queries; pick MySQL or PostgreSQL when you use their specific syntax, such as backtick identifiers or the :: cast.

Does formatting change what my query does?

+

No. Only whitespace and, if you choose, the case of keywords change. Strings, identifiers and numbers stay the same, so the query runs identically.

Why does it show an error?

+

The formatter needs to be able to read the text as SQL. An unterminated string or quote is the usual cause. Fix the quote and the output returns.

What does the SQL minifier remove?

+

It removes line breaks, extra spaces and comments, but keeps everything inside quotes and optimizer hints. The result is a single compact line that is safe to run.

Can I keep my own keyword case?

+

Yes. Choose As typed under Keywords and the original casing is preserved. UPPER and lower convert every keyword to that case.