DT
DevToolKit
Clearly labeled tools
Tools
Workspaces
Resources
Browse tools
DT
DevToolKit
Practical PDF, image, developer, and everyday tools

Clearly labeled processing for everyday tasks.

Core processing runs in the browser for most tools. Server-backed and external-provider workflows are labeled separately. Basic tools are available without signup; individual limits vary by tool.

46 unique tools4 workspacesNo signup for basic tools
Browse toolsTrust Center
Tools
All toolsPDF workspaceImage studioDeveloper workbenchGeneral tools
Product
BlogSupportContact
Company
AboutTrust CenterPrivacy PolicyTerms of Use

© 2026 DevToolKit. Practical PDF, image, developer, and everyday tools with clearly labeled processing.

In-browserServer-backedExternal preview
amanhirut32@gmail.com
HomeToolsDeveloperSQL Formatter

SQL Formatter

  • In-browser
  • No signup
  • Dialect-aware

Format or minify SQL queries directly in your browser.

Core processing runs in your browser and does not upload this file for the task.

Preparing the editor...

The guide and instructions on this page are available while the tool loads.

Continue your workflow

  • Text Diff CheckerCompare original SQL with formatted output line by line. Not a SQL-aware diff.

What this SQL Formatter does

SQL Formatter rewrites pasted SQL text in the browser with formatSql and minifySql in SqlFormatter.jsx. There is no npm SQL parser, no wire protocol, and no query execution. The sidebar Safety note says it uses custom text transformations rather than a complete SQL parser.

Input SQL starts empty. Format SQL and Minify SQL are separate buttons. Clear restores DEFAULT_SETTINGS as well as emptying both textareas. The page does not open files.

How the formatting engine and actual controls affect output

Both paths start with normalizeWhitespace (CRLF to LF, tabs to two spaces), trim, then protectQuotedStrings. Format SQL then optionally strips comments, collapses remaining whitespace to single spaces, applies keyword case, and—unless Compact mode is on—inserts line breaks and indentation. Minify SQL skips the break/indent step and always collapses whitespace.

SQL dialect
Default Standard SQL (value sql). Options: mysql, postgresql, sqlite, tsql, plsql. Extra words come from DIALECT_KEYWORDS only.
Indentation
Default 2 spaces. Also 4 spaces or Tab (\t). Used in getIndentUnit during Format SQL when compactMode is false. Minify SQL ignores indent.
Keyword case
Default UPPERCASE. lowercase or Preserve. applyKeywordCase walks the dialect keyword list longest-first with a word-boundary regex. Keywords not in that list are untouched.
Identifier case
Default Preserve. lowercase or UPPERCASE on unquoted [A-Za-z_][A-Za-z0-9_]* tokens that are not in the keyword set and not __SQL_TOKEN_ placeholders.
Remove comments
Default off in DEFAULT_SETTINGS. When on, -- to end of line and /* … */ (non-greedy, not nested) are deleted after strings are protected. minifySql’s parameter default is true, but runFormat always passes settings.removeComments, so Minify SQL follows the checkbox like Format SQL.
Compact mode
Default off. Only read by formatSql. On: no newline/indent pass; whitespace stays collapsed.
Add semicolon if missing
Default off. ensureSemicolon appends one “;” if the trimmed whole output does not already end with one.

Pretty-print line breaks are regex insertions before SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, OFFSET, VALUES, SET, JOIN variants, UNION / UNION ALL, WHEN, ELSE, plus AND, OR, and commas. Indent level increases after lines starting with CASE or WHEN and decreases before lines starting with ), END, or ELSE. That is not a full expression tree.

SQL formatting versus validation and execution

runFormat wraps formatSql or minifySql in try/catch. Empty trimmed input sets “Paste SQL to format first.” Other throws surface error.message or “Failed to process SQL.” Success does not mean the text is valid SQL.

  • No grammar parse, no EXPLAIN, no bind-parameter checking.
  • No database connection and no execution.
  • No repair, optimizer, or security scanner.
  • Formatted or minified output is still only text. It does not prove a query is valid, safe, performant, authorized, or ready to run on a real database.

Dialects, comments, quoted strings, and unsupported input

protectQuotedStrings replaces single-quoted, double-quoted, and backtick spans (with simple backslash or doubled-single-quote escapes) with __SQL_TOKEN_n__ tokens, then restoreQuotedStrings puts them back. normalizeWhitespace runs first, so tabs inside those quotes have already become two spaces and CRLF has become LF before the store is built. PostgreSQL dollar-quoting, T-SQL [bracket] identifiers, and N'…' prefixes are not dedicated cases.

  • Comments are not protected the way strings are. If Remove comments is off, collapsing whitespace can join a -- comment with following text on one line.
  • Placeholders such as ?, :name, or $1 have no special path.
  • Procedural blocks, window clauses, and keywords absent from BASE_KEYWORDS (for example WITH) do not get dedicated break rules.
  • The dialect label is not a claim that the output matches that vendor’s formatter or grammar.

How to use the current controls

  1. Paste into Input SQL. The counter under the box uses character length and lines split on CRLF, CR, or LF.
  2. Set SQL dialect under Format settings if you need extra dialect keyword strings. Default is Standard SQL.
  3. Click Indentation 2 spaces, 4 spaces, or Tab if you will use Format SQL without Compact mode.
  4. Set Keyword case and Identifier case if you want casing other than UPPERCASE keywords and Preserve identifiers.
  5. Optionally check Remove comments, Compact mode, and Add semicolon if missing.
  6. Click Format SQL (formatSql) or Minify SQL (minifySql). Empty trimmed input sets “Paste SQL to format first.” SQL summary Mode becomes Format or Minify.
  7. Read Formatted SQL. Click Copy output (Copied for 1.5 seconds on success) or Download .sql (always formatted.sql). Both stay disabled while output is empty.
  8. Click Load example to fill EXAMPLE_SQL and clear Formatted SQL. It does not click Format SQL for you.
  9. Click Clear to empty both textareas, clear the error, and restore DEFAULT_SETTINGS. Clear is disabled while both boxes are empty.

Multiple statements and malformed SQL

There is no statement splitter. A script with several “;” separators is formatted as one string. Add semicolon if missing only touches the very end of that string—it does not insert a semicolon after each statement.

Because there is no parser, unbalanced quotes, unknown syntax, and incomplete clauses usually still produce an output string. Unclosed quotes can confuse protectQuotedStrings. Review rather than assuming the engine “fixed” the SQL.

What formatting changes—and what it leaves unchanged

  • Changes: whitespace layout (and tabs→two spaces on the way in), optional keyword/identifier case for listed tokens, optional comment deletion, optional trailing semicolon, optional compact or minify collapse.
  • Does not rewrite joins, predicates, or functions into equivalents. It does not add or remove tables or filters.
  • Quoted spans are restored after keyword/indent passes, but they were already passed through normalizeWhitespace (tabs→two spaces, CRLF→LF) before protectQuotedStrings stored them.
  • Meaning is not guaranteed. The Safety note tells you to review comments and vendor-specific syntax before execution.

Privacy and browser-processing boundaries

SqlFormatter.jsx formats in the browser. It does not call trackToolEvent and does not POST the textarea to a SQL API. That is not a confidentiality guarantee: the rest of the page can still load site assets and advertising; the privacy policy describes first-party analytics for event metadata (not designed to store tool contents); clipboard, downloads, extensions, and shared devices remain outside this component.

Do not paste production credentials or customer data into a shared or untrusted tab. Local text rewrite does not encrypt the query.

Review checklist before using formatted SQL

  • Treat the output as unreadied text: it has not been validated or executed.
  • If you kept -- comments, check that whitespace collapse did not attach following clauses to the comment.
  • Confirm dialect extras you needed (for example ILIKE) were in the selected keyword list if you relied on keyword case.
  • If Compact mode or Minify SQL ran, inspect the single-line result before pasting into a client.
  • Add semicolon if missing only added at most one trailing “;”—not one per statement.
  • Download name is always formatted.sql, including minify output.

When another DevToolKit tool is more appropriate

  • Text Diff Checker — to compare the original paste with formatted output line by line (positional compare, not a SQL-aware diff).
  • JSON Formatter — when the text is JSON, not SQL. This page does not parse JSON.
  • Code Minifier — minifies JavaScript, CSS, or HTML. SQL minify is the Minify SQL button on this page, not that tool.

Frequently asked questions

Does Format SQL run as I type?

No. Output updates only when you select Format SQL or Minify SQL. Changing dialect, indent, or checkboxes does not re-run the last result. Load example fills the input and clears the output.

Is this a SQL validator or database client?

No. SqlFormatter.jsx does not parse a grammar, connect to a database, execute queries, lint, repair, or optimize. Malformed SQL is usually still rewritten. Formatted text does not prove a query is valid, safe, or authorized.

What does the dialect selector change?

It concatenates BASE_KEYWORDS with DIALECT_KEYWORDS for that value (for example ILIKE on PostgreSQL). Those lists drive keyword-case regexes and identifier-case skips. They do not switch a vendor parser.

What is the download filename?

Download .sql always uses formatted.sql and type application/sql;charset=utf-8, including after Minify SQL. Copy failed. Please copy the output manually. appears if the clipboard API rejects.

Related guides

Longer reads that pair well with this tool.

Developer guide

Useful Developer Tools Every Browser Should Have

Fourteen In-browser developer utilities for JSON, encoding, tokens, diffs, hashes, regex, SQL, UUIDs, and timestamps — fast checks without installing anything.

Related tools

Common next steps after using this tool.

Text Diff Checker

Compare two blocks of text line by line directly in your browser.

Explore more in Developer

Browse related tools or open the full workspace.

Developer workspaceAll tools