SQL Formatter

Format and beautify SQL queries with proper indentation.

Format SQL queries so they're readable: one clause per line, indented joins and subqueries, and consistent keyword case. Choose the dialect (standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle PL/SQL, BigQuery, Snowflake, Redshift or Spark SQL), uppercase or lowercase keywords, and the indent. The formatter uses the open-source sql-formatter library in your browser, so queries containing table names or customer data aren't sent anywhere. It only changes layout; it doesn't run or check the query against a database.

Common use cases

  • Make a long one-line query from a log or ORM readable
  • Tidy SQL before a code review or putting it in documentation
  • Make keyword case consistent across a team
  • Understand a complex query with many joins and subqueries

How to use

  1. Paste your SQL, or press Try an example.
  2. Choose your database dialect.
  3. Pick keyword case and indent.
  4. Copy the formatted query.

FAQ

Why choose a dialect?

Databases use different syntax for things like identifiers, string quoting and special operators. Choosing the right dialect stops the formatter misreading them.

Does it fix errors in my SQL?

No. It reformats valid SQL, and may give an error or odd layout if the query has a syntax mistake. Your database's error message is the place to check.

Does it change what the query does?

No. Only spaces, line breaks and keyword case change. Strings and identifiers are kept as written.