SQL Formatter and Minifier - Read a Long Query

SQL formatter and minifier

What this tool does

The query you need to understand is rarely the one you wrote. It came out of a log, an ORM, a colleague's message - one line, four joins, a where clause you cannot find the end of. This page puts it on separate lines so the shape becomes visible, and puts it back on one line when something else has to read it.

How to use it

  1. 1 Paste the query - one statement or a whole script.
  2. 2 Pick your indent, then press Format or Minify.
  3. 3 The text changes in the same box - copy it, or press Undo.

A comment on one line is a hazard on none

A "--" comment runs to the end of the line. Minifying removes line breaks, so a comment left in place would swallow everything after it: the query still runs, it just quietly stops halfway. That is why minifying here strips line comments entirely - and why "--" inside a string stays exactly where it is, because there it is data, not a comment.

Quotes and doubled quotes

In SQL a quote inside a string is escaped by doubling it: 'O''Brien'. A tool that closes the string at the second quote reads the rest of your name as code, and from there every keyword it finds is imaginary. The same applies to quoted identifiers - `order`, "group", [limit] are names, and a keyword inside a name is not a keyword.

It never rewrites your query

Keywords are not uppercased, parentheses are not simplified, aliases are not renamed. Only whitespace moves. That matters because a formatted query usually goes back into a file that a team reviews: a diff full of case changes hides the one line that actually changed, and lowercase keywords are a house style, not a mistake.

Formatting is not checking

This page never connects to a database, so it cannot know whether a table exists, whether your join is right, or whether the query will be slow. It reads text and moves whitespace. What it does give you is the shape - and a query whose shape you can see is one you can reason about.

SQL formatting - frequently asked questions

MySQL, PostgreSQL, SQLite, SQL Server and Oracle all work, because the tool only needs to recognise strings, comments, quoted names and clause keywords - the parts every dialect shares. Backticks, double quotes and square brackets are all treated as identifier quoting, so you do not have to tell it which database the query came from.
New
XML Formatter Indent messy XML so you can read it, or strip it down so it ships smaller. Handles RSS, CDATA and namespaces, and never rewrites your document.
Popular Today
CSS Minifier Compress CSS by stripping comments and whitespace, or expand it back with clean indentation. Keeps calc() spacing, strings and license comments intact.

Related Dev Tools

JSON Formatter Format, minify and validate JSON in your browser. Broken input is pinpointed by line and column, and a collapsible tree shows the structure.
HTML Formatter Indent messy HTML so you can read it, or strip it down so it ships smaller. Works on fragments too, and never rewrites your markup into something else.
CSS Minifier Compress CSS by stripping comments and whitespace, or expand it back with clean indentation. Keeps calc() spacing, strings and license comments intact.
XML Formatter Indent messy XML so you can read it, or strip it down so it ships smaller. Handles RSS, CDATA and namespaces, and never rewrites your document.

Other Tools You May Like

Word to PDF Convert Word to PDF for free: upload a DOC, DOCX, ODT or RTF file and download a properly formatted PDF in seconds - no registration or watermark.
PDF to Word Convert PDF to Word for free: upload a PDF and download an editable DOCX in seconds - no registration, no watermark and nothing to install.
Word Counter Free word counter: paste any text to count words, characters, sentences and paragraphs, and see the estimated reading time - nothing leaves your browser.
Character Counter Free character counter: count characters with and without spaces, plus words and lines, and check SEO limits for titles and meta descriptions.
Keyword Density Checker Free keyword density checker: paste text or a URL to see how often each word and phrase appears, with percentages for one, two and three-word terms.