Skip to content

Data

SQL Formatter

Format and compact SQL queries for multiple database dialects.

Loading tool…

Find this tool in

About this tool

What is SQL Formatter?

Make a SQL query easier to review using the dialect that matches its database. Formatting exposes joins, filters and clause boundaries without executing a query. Compact mode reduces indentation through the same parser and preserves quoted text and comments instead of deleting comment-like characters with regular expressions.

A worked example

Preserve spaces and comment markers inside a string

Example input

select 'a  -- b' as note;

Expected result

SELECT
  'a  -- b' AS note;

Select Standard SQL, uppercase keywords and two-space indentation, then format the query. The two spaces and double hyphen inside the literal remain unchanged. Compact mode also preserves that literal and retains necessary line breaks, including those around line comments. Neither operation checks tables, permissions or query results against a database.

Common mistakes and limits

  • Select the actual database dialect. Quoted identifiers, string syntax and vendor extensions are not interchangeable across all databases.
  • Formatting success is not proof that a query is safe to execute. Review updates, deletes, joins and transaction boundaries in their real context.

Features

What you can do

  • Format SQL for multiple database dialects.
  • Convert SQL keywords to uppercase, lowercase or preserve their style.
  • Choose between two-space and four-space indentation.
  • Compact indentation while preserving quoted content, comments and necessary line breaks.
  • Copy or reuse the formatted result.
  • Process every query locally in your browser.

Frequently asked questions

Questions about SQL Formatter

Why does the SQL dialect matter?

Different databases support different keywords, operators and syntax. Choosing the appropriate dialect helps the formatter interpret the query more accurately.

Does formatting change what a query does?

Formatting should only change whitespace and keyword presentation. You should still review generated output before using it in a production database.

Does this tool validate SQL against a database?

No. It formats syntax according to the selected dialect but does not connect to a database, inspect schemas or guarantee that a query will execute successfully.

Are SQL queries uploaded?

No. Formatting and compacting occur entirely inside your browser. Compact mode retains comments and necessary line breaks.

Related tools