WizzyTools

Format and beautify SQL online

Works offline · never uploaded

Pretty-print or minify a SQL query instantly in your browser, with clause-based line breaks.

Updated

/ 5 - Be the first to rate this tool Thanks for rating!

Verification failed - please try again.

How it works

  1. 1

    Paste a SQL statement into the Input box.

  2. 2

    Choose your indent.

  3. 3

    Press Format to lay it out, or Minify to compact it.

  4. 4

    Copy the formatted query.

About the SQL Formatter

Queries copied from an ORM log or a slow-query report usually come as one long line, which makes joins and conditions hard to follow. This formatter breaks a statement at its main clauses, puts each selected column and each AND or OR condition on its own indented line, and leaves the contents of quoted strings and identifiers untouched. A Minify option collapses a query back to one line.

What you can do

  • Start a new line at clauses such as SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, VALUES, UPDATE, SET, INSERT INTO and DELETE FROM.
  • Break out every join type it recognises, including INNER, LEFT, RIGHT, FULL and LEFT or RIGHT OUTER JOIN, as well as UNION and UNION ALL.
  • List SELECT, GROUP BY and ORDER BY items one per line, and split WHERE and HAVING conditions at AND and OR.
  • Indent with 2 spaces, 4 spaces or tabs, or Minify the query to a single line.

When it works best

  • Reading a query that Laravel, Django or Hibernate printed to a debug log.
  • Preparing a query for a pull request or a ticket so reviewers can see each condition.
  • Compacting a formatted query before putting it into a string in code or a CLI command.

Things to know

  • Formatting happens in the browser, so queries that mention table names or customer data stay on your device.
  • Text inside single quotes, double quotes and backticks is protected, so string values are never reformatted.
  • Clause keywords are written in upper case; other keywords and function names keep the case you typed.
  • Commas and conditions inside parentheses, such as subqueries or IN lists, stay on their parent line. SQL comments are not treated specially, and the query is not checked for syntax errors.

Frequently asked questions

SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, joins, UNION and the main INSERT, UPDATE and DELETE clauses, among others.

No. Text inside single quotes, double quotes and backticks is protected.

Content inside parentheses stays on its parent line.

No, and comments are not treated specially.