Skip to content

SQL Formatter

Format or minify SQL in your browser with indentation and keyword-case options for Standard SQL, MySQL, PostgreSQL, SQLite and T-SQL. Nothing is executed.

Developer Runs client-side Free to use
Jump to the tool
Share: X WhatsApp
Loading SQL Formatter…

About the SQL Formatter

SQL Formatter turns long or messy SQL into clean, consistently indented statements. It handles SELECT, INSERT, UPDATE, DELETE, CREATE and ALTER statements, joins, WHERE, GROUP BY, HAVING, ORDER BY, UNION, CASE expressions and nested subqueries, with a choice of 2 spaces, 4 spaces or tabs and UPPERCASE, lowercase or preserved keywords.

Formatting uses the open-source sql-formatter library, bundled on this site, with dialect options for Standard SQL, MySQL/MariaDB, PostgreSQL, SQLite and SQL Server. Strings, quoted identifiers, comments and placeholders are kept as written. It is a formatter only: it does not validate SQL against a database, optimise queries, execute anything or connect to any database.

How to use

  1. Paste your SQL into SQL input, or click Sample query.
  2. Choose the dialect, the indentation and the keyword case.
  3. Click Format SQL — or Minify SQL to put it on one line.
  4. If the SQL is incomplete or uses another dialect’s syntax, you’ll see a clear message and your input is left unchanged.
  5. Copy the result or download it as a .sql file.

Key features

  • Formatting for common statements, joins, CASE, UNION and subqueries.
  • Indentation of 2 or 4 spaces or tabs.
  • Keyword case: UPPERCASE, lowercase or preserve.
  • Dialect choice: Standard SQL, MySQL/MariaDB, PostgreSQL, SQLite, SQL Server.
  • Strings, quoted identifiers, comments and placeholders (?, $1, :name, @name) preserved.
  • Minify mode that keeps comments valid by converting -- comments to /* … */.

Best practices

  • Pick the dialect that matches your database so quoting and placeholders are recognised.
  • Agree on a keyword case and indentation for your team and use them consistently.
  • Review formatted SQL before committing — formatting does not check that it runs.
  • Keep secrets and customer data out of queries you paste into any tool.
  • Run queries in a development database before production.

Benefits

  • Readable queries for code reviews, documentation and debugging.
  • Consistent style across a team.
  • No database connection or installation needed.
  • Your SQL never leaves the browser.

Frequently asked questions

Does this tool run or validate my SQL?

No. It only rearranges whitespace and keyword case. It does not execute SQL, connect to a database or confirm the query is valid.

Why did formatting fail?

The formatter could not parse the statement — usually because it is incomplete or uses syntax from a different dialect. Try another dialect or fix the statement; your input is never changed.

Are string literals and comments changed?

No. Text inside quotes and comments is kept exactly as written. Keyword casing only applies to SQL keywords.

Which placeholders are supported?

Positional ? placeholders, numbered $1 placeholders and named :name and @name placeholders.

What does minify do with comments?

Line comments (--) are converted to /* … */ so they remain valid on a single line; block comments are kept.

Which library is used?

The open-source sql-formatter library (MIT licence), version 15.9.0, hosted on this site rather than loaded from a CDN.