SQL Formatter Online

Paste a messy SQL query and get a clean, properly indented one. Works with MySQL, PostgreSQL, SQL Server, Oracle, SQLite and a dozen other dialects.

Your queryCtrl + Enter
Result

Why format SQL?

A query written on a single line, generated by an ORM or copied from logs, is hard to read. A SQL beautifier puts each clause (SELECT, FROM, JOIN, WHERE, GROUP BY…) on its own line and indents columns and conditions. You can spot a missing join, a misplaced OR or a column missing from the GROUP BY at a glance.

Consistent SQL style also makes code reviews easier and keeps Git diffs small: when the whole team formats queries the same way, changes only show the logic that moved.

How to use this SQL formatter

  1. Paste your query in the left box (or click “Example”).
  2. Pick your database dialect so its specific syntax is recognized: MySQL backticks, PostgreSQL :: casts, SQL Server brackets and so on.
  3. Choose keyword case and indentation, then click Format or press Ctrl + Enter.
  4. Copy the result or download it as a .sql file.

Minify SQL

The Minify button does the opposite: it strips comments (-- and /* */) and extra whitespace to produce a one-line query, handy for embedding SQL in a string or a config file. String literals are never touched.

Your queries stay private

Formatting happens entirely in your browser with JavaScript. Nothing is uploaded, so you can safely format queries that contain internal table names or sensitive data.

FAQ

Does the SQL formatter fix syntax errors?

No. It changes the layout without changing what the query does. If the query has an error, it will still be there after formatting, but it is usually much easier to spot.

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark SQL and DB2.

Should SQL keywords be uppercase?

It is not required, since SQL keywords are case-insensitive. Uppercase remains the most common convention because it clearly separates keywords from table and column names.

Can I format several queries at once?

Yes. Separate them with semicolons: each query is formatted and separated from the next by a blank line.

More free tools