Internative Logo

SQL Formatter: Format and Read SQL Queries in Your Browser

SQL Formatter: Format and Read SQL Queries in Your Browser

A SQL query that arrives on one line, copied from a log or an ORM's debug output, is hard to read and harder to review. Formatting puts each clause on its own line and indents the nested parts, so you can see what the query does. The tool below formats SQL you paste. It runs in your browser, so your queries are not sent anywhere.

SQL formatter

Lay out an SQL query with indentation and one clause per line. The query is formatted as text and never run.

What you enter never leaves your browser. Nothing is sent or stored.

How to use the formatter

  1. Paste your SQL into the input field.
  2. Press Format.
  3. Copy the formatted query from the output field.

The formatter changes layout only: line breaks, indentation and spacing. It does not run the query, connect to a database or check table and column names. If the text cannot be read as SQL, the tool shows an error rather than output.

What formatted SQL makes visible

  • The shape of the query. SELECT, FROM, WHERE, GROUP BY and ORDER BY each start a line, so you can find a missing condition at a glance.
  • Joins and their conditions. Each JOIN starts its own line with its ON condition beside it, which makes a wrong or missing join condition easy to spot.
  • Nesting. Subqueries and parenthesized groups are indented, so you can see where one ends.
  • Differences in a review. A query written in a consistent layout produces clean diffs when someone changes one condition.

Things to watch

  • Layout is not correctness. A well-formatted query can still be wrong, slow or unsafe. The formatter does not test it.
  • One general layout. The tool uses a general SQL grammar, not one specific to your database. Syntax that belongs to a single engine, such as a vendor-specific function or a procedural block, may be laid out less neatly.
  • Do not build queries from text. Formatting a query that you assemble by concatenating user input does not protect it from injection. Use parameterized queries.
  • Check the result before you run it. Whitespace inside quoted strings should be unchanged, but compare when a query contains long text values.

Where it comes up

Reading a query from an application log, reviewing a pull request that contains SQL, cleaning up a report query before you hand it on, or documenting a query for a colleague. When queries behind your product have become hard to understand and change, we can help rebuild that layer through custom software development and enterprise software solutions.

Frequently asked questions

Does my SQL leave my browser?

No. Formatting happens in the page on your device. The tool does not connect to a database and does not send or store your query.

Does it change what my query does?

No. It changes line breaks, indentation and spacing, not the statement itself. Run your usual tests on the formatted version if the query matters.

Which SQL dialects does it support?

It formats with one general SQL grammar. Standard statements such as SELECT, INSERT, UPDATE and DELETE are the safe case. Engine-specific syntax may not format as you expect.

Does it check whether my SQL is valid?

Not against a database. It does not know your tables or columns, so it cannot tell you that a name is wrong. It only reports when the text cannot be read as SQL at all.

Can it minify SQL?

No. It formats for readability. It does not remove whitespace or shorten the query.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.