SQL Formatter & Beautifier

Beautify long SQL queries with clause-per-line layout and consistent keyword case. Pick your database dialect so its syntax is parsed correctly.

Loading tool…

About the SQL Formatter

The formatter uses the open-source sql-formatter library, which tokenizes and parses each dialect with its own rules. That matters: backtick identifiers are MySQL/MariaDB/BigQuery syntax, [brackets] and TOP are T-SQL, :: casts and dollar-quoted strings are PostgreSQL, QUALIFY is Snowflake/BigQuery. Choosing the matching dialect avoids parse errors and keeps those constructs intact.

Each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — starts a new line, select-list columns are placed one per line, and subqueries and CTEs are indented. Keywords sets the case of keywords, data types and built-in functions; identifiers and string literals are never changed. AND/OR on new line first puts logical operators at the start of lines, which makes long WHERE conditions easier to comment out.

Multiple statements separated by ; are formatted one after another. The formatter does not validate table or column names and does not execute anything — it only rearranges whitespace and keyword case, so the query means exactly the same. Comments (-- and /* */) are preserved. Your SQL is processed in the browser, which makes it safe for queries that reveal schema details.

How to use it

  1. Paste one or more SQL statements.
  2. Select your database dialect.
  3. Choose keyword case and indentation.
  4. Copy or download the formatted query.

Frequently asked questions

Which SQL dialects are supported?
Standard SQL, MySQL, MariaDB, PostgreSQL, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Spark SQL and Amazon Redshift.
Why do I get a parse error?
Usually the dialect does not match the syntax (for example TOP 10 with MySQL selected) or the statement uses a templating placeholder like {{ var }}. Switch dialects or replace placeholders with literals.
Does formatting change the query result?
No. Only whitespace and the case of keywords change. Quoted identifiers and string values are left exactly as written.
Should SQL keywords be uppercase?
SQL is case-insensitive for keywords, so it is a style choice. Uppercase keywords remain the most common convention because they separate structure from table and column names.

Related tools