SQL Formatter

Turn a long one-line query into readable SQL with each clause on its own line and consistent indentation. Choose the dialect so that vendor-specific syntax, quoting and functions are recognised, then decide on keyword case and indent width. Your query is only re-formatted; it is never executed.

Format & Validate Runs in your browser

Format Your SQL Query

This tool only re-indents text. It never connects to a database and never runs your SQL.

How to Use the SQL Formatter

  1. Paste your SQL, or keep the sample query.
  2. Select the SQL dialect that matches your database, then the keyword case, indentation and where AND / OR should go.
  3. Press Format.
  4. Copy the formatted SQL or download it as formatted.sql.

About This Tool

Developers reviewing queries from logs or ORMs, analysts tidying SQL before sharing it, and teams that want a consistent style in code reviews and documentation.

Input: SQL text  ยท  Output: Formatted SQL.

Features and Limitations

Features

  • 18 dialects including MySQL, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery, Snowflake and Spark.
  • Keyword case: upper, lower or preserved.
  • 2-space, 4-space or tab indentation.
  • Handles several statements separated by semicolons.
  • Powered by the MIT-licensed sql-formatter library, running locally.

Limitations

  • The formatter does not validate SQL or know your schema, so a query that looks fine here can still fail in your database.
  • Unusual vendor extensions, procedural blocks and very exotic syntax may be laid out imperfectly or rejected; try a more specific dialect.
  • Comments are kept but their position can shift slightly.
  • Formatting changes only whitespace and keyword case, never table, column or string content.
  • Results are computed in your browser; nothing you enter is sent to a server.

Example

select id,name from users where active=1 and age>30 comes out with SELECT, FROM and WHERE each on their own line, the columns id and name indented under SELECT, active = 1 under WHERE and the AND condition on a line of its own.

Frequently Asked Questions

Does the tool run my SQL?

No. It only tokenises the text and prints it with new indentation. There is no database connection and no query is executed.

Which dialect should I choose?

Choose the one that matches your database. Standard SQL is a safe default, but MySQL backticks, PostgreSQL operators such as ::, or T-SQL brackets are only understood when the right dialect is selected.

Why do I get a parse error?

Usually there is an unclosed quote or bracket, or the query uses syntax the selected dialect does not know. Check the position in the message and try another dialect.

Will formatting change what my query does?

No. Only whitespace, line breaks and (optionally) keyword case change. Strings, identifiers and numbers are left as they are.

Is my query stored or sent anywhere?

No. The formatting library runs in your browser and your SQL stays on your device.

Related Tools

More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.