SQL Formatter

Format SQL queries for MySQL, PostgreSQL, SQL Server, SQLite, Oracle, BigQuery and more: indent clauses and capitalise keywords.

Runs in your browserNo sign-upWorks offline
Ctrl+Enter to run
Input121 characters
Output
✓ ReadySample content shown

What the SQL Formatter does

The SQL Formatter turns a long, single-line query into readable SQL, with each clause on its own line, joins and conditions indented, and keywords and functions in capitals if you like. Choose your database so its own syntax is understood: MySQL, MariaDB, PostgreSQL, SQL Server, SQLite, Oracle PL/SQL, BigQuery or standard SQL. Formatting only changes spacing and letter case, so the query does exactly the same thing.

How to use it

  1. Paste one or more SQL statements on the left.
  2. Choose your database.
  3. Choose capitals and indent size.
  4. Copy or download the formatted SQL.

Example

The sample report query, which joins orders, customers and order items, groups and sorts the totals, becomes a tidy block starting SELECT, then FROM with each JOIN on its own line, then WHERE, GROUP BY, HAVING and ORDER BY, with SUM in capitals.

Why format SQL

Formatted queries are far easier to review in pull requests and to debug: a missing join condition or a misplaced AND stands out when each condition sits on its own line. Many teams adopt one style, such as capital keywords and 2-space indents, so changes show only real differences.

Several statements separated by semicolons are formatted together with a blank line between them. Comments are kept.

Questions people ask

Is my code or data uploaded?

No. Everything runs in your browser, so config files, queries, logs and keys stay on your device. That makes it safe to use with work data.

Will it fix errors in my SQL?

No. It formats the query as written. A query with a syntax error may not format, and the message shows roughly where the problem is.

Does it run the query?

No. Nothing connects to a database; it only rearranges the text.

Which database should I choose?

The one the query runs on. It matters for special syntax such as backtick names in MySQL, :: casts in PostgreSQL or square brackets in SQL Server; for simple queries any choice works.

Related tools