SQL Formatter

Lay out a query so its structure is readable.

Code Formatters Free, no sign-up Runs in your browser

SQL Formatter tool

About the SQL Formatter

SQL Formatter takes a query written as one long line and lays it out so you can see what it does. Major clauses start on their own lines, join conditions line up under their joins, lists of columns are broken sensibly, and subqueries are indented inside their parentheses.

Keyword case is normalised to whichever convention you prefer, with uppercase keywords against lowercase identifiers being the most common choice because it makes the structure of a query visible at a glance. String literals, quoted identifiers and comments are detected and passed through exactly as written.

This is a layout tool rather than a parser, which means it handles dialect differences gracefully and never refuses to format something it has not seen. It will not validate your query or tell you whether it will run; it will make a four-hundred-character line into something a person can read, which is usually the problem at hand.

How to use the SQL Formatter

  1. Paste your queryOne statement or several.
  2. Choose keyword case and indentUppercase keywords is the usual convention.
  3. Press FormatThe laid-out query appears below.
  4. Copy it back into your editorFormatting changes whitespace and keyword case only.

Features

  • Major clauses on their own lines
  • Joins and their conditions aligned
  • Subqueries indented inside parentheses
  • Uppercase, lowercase or unchanged keyword case
  • Strings, quoted identifiers and comments preserved
  • Handles several statements separated by semicolons
  • Copy or download the result

Who uses this tool

The sql formatter is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Reading a query pulled from application logs
  • Reviewing a colleague's query before approving it
  • Tidying a query before adding it to a repository
  • Understanding a generated query from an ORM
  • Teaching how a complex query is structured

Frequently asked questions

Which SQL dialects are supported?

The formatter works at the token level and recognises the keywords common to standard SQL plus the widely used extensions, so queries for PostgreSQL, MySQL, SQL Server, SQLite and others all format sensibly. It does not enforce any dialect's rules.

Does it change what my query does?

No. Only whitespace and keyword case change. Identifiers, literals and the order of everything are untouched, so the query executes identically.

Why uppercase keywords?

It is the long-standing convention, and it works: uppercase keywords against lowercase table and column names make the shape of a query visible without reading it word by word. The option exists if your team prefers otherwise.

Are my string literals safe?

Yes. Quoted strings and quoted identifiers are detected and passed through byte for byte, including ones containing keywords or semicolons.

Does it validate the query?

No. It formats text. Whether the query is correct, or safe to run, is a question only your database can answer.

Is my query uploaded?

No. Formatting happens in your browser, which matters because queries routinely contain table names and values you would not send to a third party.

If the sql formatter is not quite what you need, these other free tools solve closely related problems.

JSON Formatter

Pretty-print and validate JSON, with the exact line and column of any error.

Developer Tools Use tool

CSV Viewer

View CSV data as a proper table you can sort, search and page through.

Developer Tools Use tool

XML Formatter

Pretty-print XML with proper indentation, and catch malformed documents.

Code Formatters Use tool

JavaScript Formatter

Format JavaScript with consistent indentation, spacing and statement breaks.

Code Formatters Use tool

CSV to JSON Converter

Turn spreadsheet data into JSON, or JSON records back into CSV rows.

Developer Tools Use tool