SQL Formatter

Converter

Format and indent SQL queries with a regex-based prettifier for SELECT, INSERT and UPDATE statements, keeping comments and uppercasing keywords. Keeps comments.

Input → Output
12 lines · 221 chars
SQLInput
SQLOutput

About SQL Formatter

SQL produced by an ORM or grabbed from logs is often crammed onto one long line, with keywords, columns, and subqueries all jammed together and hard to read. This tool formats SQL locally in your browser — wrapping, indenting, and aligning keywords so SELECT, JOIN, and WHERE structures stand out for review and tuning. For instance, SELECT id,name FROM users WHERE age>18 is re-indented across lines with SELECT, FROM, WHERE highlighted, making the query structure obvious.

How to Use

  1. Open the SQL Formatter tool
  2. Select the source and target formats
  3. Adjust the output options as needed
  4. Click the Convert button; results appear in real time
  5. Copy or export the result

Use Cases

  • Beautify log SQL — Format a one-line slow query from logs to see its JOIN and subquery structure.
  • Review ORM output — Format ORM-generated SQL to confirm it produces the query you expected.
  • Prep for tuning — Lay out a complex query clearly to spot redundant subqueries or missing index conditions.
  • Unify team style — Normalize indentation across colleagues' varied SQL for easier code review.
  • Teaching — Expand nested queries into layers to explain execution logic to newcomers.
  • Format embedded SQL — Extract inline SQL from application code and format it to review the query logic before debugging.
  • Align migration scripts — Reformat multiple SQL migration files consistently to maintain a uniform style across the codebase.

FAQ

Does it change the query result?

No. Formatting only adjusts whitespace, line breaks, and indentation; keywords, columns, and logic are untouched, so semantics and results stay identical.

Which SQL dialects are supported?

It formats standard SQL and common dialects like MySQL and PostgreSQL well. A few vendor-specific syntaxes may not be fully recognized but usually still format acceptably.

Are keywords uppercased?

It typically normalizes keywords to uppercase for readability, while column names and values keep their original case.

Can it minify to one line?

This tool focuses on pretty-printing. To collapse multi-line SQL for embedding, remove the line breaks manually or use a compact mode where available.

Are comments preserved?

Single-line (--) and multi-line (/* */) comments are generally kept and placed sensibly, though comments in odd positions may be re-wrapped — verify quickly after formatting.

Will a very long SQL statement make it lag?

This tool runs locally in your browser and only rewraps whitespace and indentation at the token level — it never executes a query or parses the data — so SQL reaching thousands or tens of thousands of lines still formats smoothly. A statement with an extreme number of deeply nested subqueries may show a brief pause during the first highlight pass; usually a single re-render resolves it. If it feels stuck, split the statement into chunks, or strip non-SQL noise from the log line first, rather than trying to format one giant statement all at once.

If I paste production SQL, is it uploaded anywhere?

No. Formatting and syntax highlighting happen entirely in your browser; the SQL text is never sent to a server and is not logged or used for training, so you can safely paste slow-query logs or statements containing sensitive column names. For intranet or highly regulated environments, still follow your company's policy — e.g., redact schema and table names — since local processing only keeps the data from leaving your browser and can't protect you from other network-layer risks.

Advertisement