UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

About·Changelog·Privacy Policy·Terms of Service·Contact
HomeDatabase & SQL ToolsSQL Formatter

Related Tools

SQL Query Builder

SQL Query Formatter & Beautifier

Format and beautify SQL queries — uppercase keywords, indent subqueries, break lines before major clauses. Handles SELECT, INSERT, UPDATE and CREATE TABLE.

You Might Also Like

All Database & SQL Tools

SQL Query Builder

Build SELECT queries visually: pick a table, add columns, JOIN another table, set WHERE conditions and ORDER BY — then copy the formatted SQL.

Text ↔ Hex

Write text as uppercase hex bytes using space, comma, 0x or no separator, and parse pasted hex dumps into readable output.

Text ↔ Base64

Encode text to Base64 or unpack a Base64 string into plain characters, with full Unicode handling and a live encoding-overhead readout.

Line Counter

Count total, empty, non-empty, unique and duplicate lines at once, then pull out a deduplicated version of the list ready to paste elsewhere.

Copy a query out of a log file and it lands as a single line of lowercase keywords with no indentation. This formatter reads that string and returns SQL a human can follow: major clauses each start on a new line, keywords are uppercased, subqueries indent one level, and compound phrases like GROUP BY stay together instead of splitting across lines.

The tokenizer handles single-quoted strings (with the '' escape), double-quoted and backtick identifiers, line comments (--), block comments, /* */), and qualified names like s.name. Everything runs in the browser; no query is uploaded to a server.

Worked Example: a Multi-Clause SELECT

The page loads with a deliberately ugly query on one line: select s.name, count(*) as failures, avg(r.duration_ms) as avg_ms from requests r join services s on s.id = r.service_id where r.status >= 500 and r.created_at >= now() - interval '1 hour' group by s.name having count(*) > 10 order by failures desc limit 20; The formatter breaks it into 9 lines: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line, and every keyword is uppercased. Press Load Sample to cycle through an UPDATE with a subquery, a CREATE TABLE with column definitions, and a multi-row INSERT.

What Each Formatting Toggle Does

  • Keyword case uppercases, lowercases or preserves the original casing of SQL keywords. Identifiers and string literals are never changed. The default is UPPER because that is the convention in every major SQL style guide.
  • Indent size sets the number of spaces per nesting level: 2 (compact), 4 (readable) or 8 (tab-style). Subqueries and parenthesised blocks that contain a major clause indent one level; simple function calls like COUNT(*) stay inline.
  • One column per line puts each comma-separated column on its own line. Off by default; turn it on for wide SELECT lists that are hard to scan horizontally.

Format Notes: Tokenizing and Quoting

String literals are preserved exactly, including the doubled single quote that SQL uses to escape a literal apostrophe. A string like 'it''s here' survives a round-trip unchanged. Line comments and block comments are kept in the output and indented to the current depth, so a 3-line /* ... */ block above a WHERE clause stays where you put it.

Qualified names with dots (r.service_id, public.users) are treated as a single token so they do not get split across lines. Identifiers wrapped in double quotes or backticks ("order", user) are kept verbatim, including the quoting characters.

Not a Substitute for a SQL Parser

The formatter tokenizes text, not semantics. It does not validate syntax, resolve table names, check types, or detect missing FROM clauses. A query with a syntax error is still formatted, and the error is still there afterward. Use it to make a query readable before debugging it in a database client, not as a linting step that catches mistakes.

43 words

Formatting Options