SQL Formatter

Format SQL for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery and Oracle.

Your SQL is formatted locally in your browser and nothing is uploaded to a server.

Working with NoSQL too? Try the MongoDB Query Formatter.

About SQL Formatter

This SQL formatter cleans up messy, single-line or unindented queries into readable, consistently styled SQL. Pick your dialect — MySQL, PostgreSQL, SQL Server (T-SQL), SQLite, BigQuery, Oracle (PL/SQL) or standard SQL — and the tool reflows SELECT, FROM, JOIN, WHERE and the rest with proper indentation. As a SQL beautifier it lets you choose 2- or 4-space indents and optionally uppercase keywords for a uniform house style. It is handy for developers reviewing pull requests, QA engineers reading logged queries, and data analysts who need to pretty print SQL straight from an ORM or a one-line dump. Use it to format SQL online before committing, diffing or sharing. Everything runs locally in your browser, so your queries are processed on your device and your data never leaves your browser.

Features

How to use the SQL Formatter

  1. Paste your SQL into the SQL input box.
  2. Select your database dialect from the dropdown (e.g. PostgreSQL or MySQL).
  3. Pick 2 or 4 space indentation and toggle UPPERCASE keywords if you want.
  4. Read the beautified result in the Formatted SQL panel.
  5. Copy the output or download it as query.sql.

Example

Input

select id,name from users where active=1 order by name desc;

Output

SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
ORDER BY
  name DESC;

A single-line query reflowed with 2-space indent and uppercase keywords.

Common errors & troubleshooting

Frequently asked questions

What is the SQL Formatter and when should I use it?
It is a SQL beautifier that reflows messy or single-line queries into clean, indented SQL. Use it before committing, diffing in a pull request, or sharing a query with your team.
Which SQL dialects does the SQL Formatter support?
MySQL, PostgreSQL, SQL Server (T-SQL), SQLite, BigQuery, Oracle (PL/SQL) and standard SQL. Pick the one matching your database from the dropdown.
How do I change the indentation width in the SQL Formatter?
Use the 2 spaces / 4 spaces switch to set how deeply nested clauses are indented in the formatted output.
Can the SQL Formatter uppercase keywords automatically?
Yes. Toggle UPPERCASE keywords to standardise SELECT, FROM, WHERE, JOIN and the rest across the whole query.
Does the SQL Formatter run or connect to my database?
No. It only reformats the query text in your browser and never executes it or connects to any database.
Is my SQL sent anywhere when I format it?
No. Your query is processed locally in your browser and your data never leaves your device, so nothing is uploaded to a server.

Related tools

All ArrayKit tools