SQL Formatter: Format or Minify SQL for MySQL, PostgreSQL, SQL Server and More

What is it?

The SQL Formatter makes long queries easy to read and review. Paste any SQL, pick your database and get it formatted with the open-source sql-formatter library: SELECT columns one per line, JOINs and WHERE conditions lined up, and keywords in UPPER or lower case. One option squeezes it back onto a single line.

Who is it for?

Developers and analysts sharing queries in reviews or tickets, students tidying assignment answers, and anyone who copied a query from a log on one line.

How to use it

  1. Paste your query into SQL to format, or tap Try a sample.
  2. Choose the Database (Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle PL/SQL, BigQuery, Snowflake, Redshift, Spark, Db2, Trino), the Keywords case (UPPER case, lower case or Keep as typed) and the Indent.
  3. Tick One line (minify) to get a single line instead.
  4. Copy the Formatted SQL or download it as query.sql.

Worked example

Paste select a,b from t where c=1 and d>2. The result is SELECT on its own line with a and b indented below it, then FROM t, then WHERE c = 1 with AND d > 2 on the next line, keywords in capitals. Minify removes comments and extra spaces, but text inside quotes is kept exactly as written.

Is my code uploaded?

No. The checker is downloaded once from a public download server (jsDelivr or cdnjs) and then runs inside your browser. Your code never leaves your device, so it is safe for work and client projects.

Errors and how to fix them

  • Could not format this SQL: …: the formatter met syntax it does not understand. Pick the right database, for example SQL Server for SELECT TOP 5 [Name], and check for unclosed quotes or brackets.
  • Output is valid but the query fails: formatting does not check correctness. Use the SQL Checker for that.
  • Nothing happens, or a “Could not load” message: the first use downloads the library. Check your internet connection, turn off an ad or script blocker for this site, and reload the page.

Open the tool: SQL Formatter

Still stuck?

Contact support. Tell us which tool or page you were using, what you tapped, what you saw, and your phone or computer and browser (for example: Android phone, Chrome). We reply by email.

Questions, or an error not listed here?

Tell us in the comments: what you were doing, the exact message you saw, and your device and browser. We read every comment and add new fixes to this article.