SQL

SQL Formatter

Format and beautify SQL queries with proper indentation, or minify them to a single line.

Indent:
Opens your print window: choose "Save as PDF". The file is named "SQL Formatter - MondayTool".
About this tool

Last updated:

Format and minify SQL queries

This SQL formatter turns a messy one-line query into readable, indented SQL. It can also do the opposite and minify a query into a single line. You choose the indent size and whether keywords are upper or lower case.

How to use it

  1. Paste your query into SQL Input. A sample query is loaded to start with.
  2. Choose Format or Minify.
  3. For Format, pick an Indent of 2 or 4 spaces and switch Uppercase keywords on or off.
  4. Click Format SQL (or Minify SQL), then Copy the output.

How it works

The tool splits your SQL into tokens: keywords, identifiers, strings, numbers, comments and punctuation. In Format mode, clause keywords such as SELECT, FROM, WHERE, JOIN, GROUP BY and ORDER BY start a new line. AND and OR go on indented lines, and each comma in a clause starts a new line. A subquery in brackets is indented one level deeper. Other reserved words like NULL, IN or DISTINCT only change case.

Minify removes comments and collapses whitespace between tokens. String literals and quoted identifiers are kept exactly as written.

What it recognises

  • Single-line (--) and block (/* */) comments.
  • Strings in single quotes, including N'', E'', X'' and B'' prefixes.
  • Quoted identifiers in "double quotes", backticks and [square brackets].
  • Multi-character operators such as >=, <>, :: and ->>, and parameters like $1, @name and :name.

Assumptions and limits

  • The formatter is not tied to one dialect and does not check that your SQL is valid. It reshapes text only.
  • Longer constructs such as CASE ... END and window functions are kept on the line they start on, not broken up.
  • Format mode does not remove comments. Only Minify does.
  • Click the button after changing mode or options. The output does not refresh on its own.
  • The text is processed in your browser.

Frequently asked questions

Does formatting change what my query does?

It only changes whitespace and keyword case. Strings and quoted identifiers stay as written. Still, review the output before you run it on important data.

Can I keep my keywords lowercase?

Yes. Turn off Uppercase keywords before you click Format SQL, and keywords come out in lowercase.

Why would I minify SQL?

A one-line query is easier to paste into a log message, config value or code string. Minify also strips comments, so check you do not need them first.

More to explore

Related Developer Tools

Browse all tools from the same category.

Showing 1-2 of 49