UtilityToolsLab

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

Free eBooks·About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeDatabase & SQL ToolsSQL Formatter

Related Tools

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

Case Converter

Convert text between UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, and kebab-case.

Lorem Ipsum

Placeholder text in 20 languages — English, Bengali, Hindi, Arabic, Spanish, French, Chinese and more. Paragraphs, sentences, words, lists, optional emoji.

English Lorem Ipsum

Generate free English Lorem Ipsum dummy text for web design, layouts, and mockups. Classic Latin filler text in paragraphs, sentences, words, or lists.

Bangla Lorem Ipsum

Generate free Bangla (Bengali) Lorem Ipsum dummy text for web layouts and mockups. Bengali script filler in paragraphs, sentences, words, or lists.

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