curly{bits}

curlybits / SQL Formatter

SQL Formatter & Beautifier

Paste a messy or one-line SQL query and get it back neatly indented, with each clause on its own line and keywords in the case you like. It supports 18 dialects, from MySQL and PostgreSQL to SQL Server, Oracle, BigQuery and Snowflake, and your queries never leave your browser.

Input SQL
Formatted SQL

How to use the SQL Formatter & Beautifier

  1. Paste your SQL into the left box, drop a .sql file on it, or click Load sample.
  2. Pick your database under Dialect, so its special syntax is understood.
  3. Choose uppercase or lowercase keywords, the indent, and whether AND/OR start each line.
  4. Copy the result, or download it as a .sql file.

Why format SQL?

Queries copied from logs, ORMs and BI tools often arrive as one long line. Putting each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) on its own line and indenting the columns makes it much easier to spot a missing join condition, a wrong filter or a column you didn't mean to select. Consistent formatting also makes code reviews and diffs far cleaner.

select id,name from users where active=1 and city in ('Bangkok','Phuket') order by name

becomes

SELECT
  id,
  name
FROM
  users
WHERE
  active = 1
  AND city IN ('Bangkok', 'Phuket')
ORDER BY
  name

Supported dialects

Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, Google BigQuery, Snowflake, Amazon Redshift, DuckDB, ClickHouse, Spark SQL, Hive, Trino/Presto, IBM Db2, SingleStore and TiDB. Picking the right one matters for things like backtick-quoted names in MySQL, :: casts in PostgreSQL, square brackets in SQL Server and QUALIFY in Snowflake and BigQuery.

Formatting options

  • Keywords: UPPERCASE is the classic style. Lowercase is popular in modern codebases. As typed leaves them alone.
  • AND/OR at line start puts logical operators at the beginning of each condition, which makes it easy to comment one out.
  • Align columns lines up clause keywords in a fixed-width left column, a style some teams prefer for long reports.

The formatter only changes whitespace and keyword case, so the query does exactly the same thing. It's powered by the open-source sql-formatter library, running in your browser.

Frequently asked questions

Is my SQL sent to a server?

No. Formatting happens in your browser, so table names, customer data and credentials in your queries stay on your computer.

Does it check that my SQL is valid?

It reads the query's structure and reports where it can't make sense of it, with a line and column. It doesn't connect to a database, so it can't tell whether tables or columns exist.

Why does it say it can't format my query?

Usually it's syntax from another database. Pick the matching dialect: for example, MySQL backticks, SQL Server square brackets or PostgreSQL :: casts. Unbalanced brackets or quotes also stop it.

Can it format stored procedures and multiple statements?

Yes. Separate statements with semicolons and each one is formatted, with a blank line between them. Use the PL/SQL or T-SQL dialect for Oracle and SQL Server procedures.

Add this SQL formatter to your website

Free for blogs, schools and businesses. Copy the code below and paste it into your page's HTML. The tool works exactly like this one and runs in your visitors' browsers, so nothing is uploaded. Please keep the credit line so others can find it too.

Preview embed ↗