SQL Formatter
Runs 100% in your browserFormat, beautify, and minify SQL in your browser — 10 dialects, heuristic lint hints, keyword casing, protected strings, statement splitting, diagnostics, and session history. No upload, no execution.
SQL input
Formatted SQL
Formatting review
WaitingSession history (last 8 — in-memory only)
Frequently asked questions
An SQL Formatter (also called an SQL Beautifier or SQL Pretty Printer) turns dense, unreadable SQL into a structured layout with indentation, keyword casing, clause line breaks, preserved comments, and statement separation. It makes queries easier to read, review, debug, and commit — without executing the SQL or connecting to a database.
Paste SQL into the input editor or open a local .sql, .ddl, or .dml file. Choose a dialect hint, indentation style, keyword casing, comma layout, AND/OR line placement, blank-line spacing, comment policy, and statement splitting. Click Format SQL or press Ctrl+Enter to see the result, then copy or download it.
The formatter provides 10 dialect hints: Generic SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server / T-SQL, Oracle / PL-SQL, BigQuery, Snowflake, and Amazon Redshift. Each dialect unlocks additional recognized keywords so casing and clause detection are more accurate for that vendor. The hints do not claim complete parser compatibility or vendor-specific grammar validation.
No. The formatter never connects to a database, sends a query to a server, runs SQL, reads schemas, or checks permissions. All tokenizing and layout work runs locally in your browser tab. You can open DevTools → Network and verify zero outbound requests.
Yes. Single-quoted strings, double-quoted identifiers, backtick-quoted names, dollar-quoted strings ($$...$$), line comments (--), and block comments (/* */) are all tokenized before formatting. Keywords inside strings are never recased. Semicolons inside quoted strings never trigger statement splitting.
Recase Only applies keyword casing (UPPERCASE, lowercase, or Preserve) without changing any whitespace or indentation. It is useful when you want to normalize keyword casing across a query without reformatting its layout — ideal for code reviews or style-guide enforcement on existing formatted SQL.
Minify strips all whitespace, indentation, and comments to produce the most compact single-line SQL possible. This reduces file size for embedded SQL strings, log payloads, or wire-format query serialization. Semicolons inside quoted strings are still protected.
Yes. The Comma setting offers three options: Inline (comma stays at end of each value, same line), New line trailing (comma at end, clause moves to next line), and New line leading (comma placed at the start of the next line — the "leading comma" style popular in many SQL style guides).
Yes. The formatter places readable breaks around SELECT, FROM, JOIN, ON, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, UNION, WITH, VALUES, SET, RETURNING, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, and TRUNCATE when the token context permits. Multi-word JOIN modifiers (LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN etc.) are kept together on one line.
Yes. Parenthesis depth is tracked to handle nested expressions, function calls, subqueries, IN lists, CASE expressions, and VALUES lists. Common Table Expressions using WITH and RECURSIVE are detected as major clause boundaries. The review panel warns when parentheses are left open.
Yes. The Blank lines setting lets you add 0, 1, or 2 blank lines between semicolon-delimited statements. This is useful for scripts with multiple DDL or DML statements where visual separation helps readability.
Yes. The Preserve comments checkbox (enabled by default) keeps both line comments (--) and block comments (/* */) in the formatted output at their original positions. Unchecking it strips all comments for a clean output — useful when comments contain noise or version metadata.
Yes. Use Open .sql file to load a local .sql, .ddl, or .dml file. Processing is performed entirely in page memory. The client contains no fetch, XMLHttpRequest, navigator.sendBeacon, localStorage, or sessionStorage usage. Your SQL is never transmitted, persisted, or executed.
Formatting changes whitespace, indentation, and keyword casing for readability — it does not prove the SQL is syntactically correct for a specific database engine. SQL validation checks that the query parses correctly against a grammar. ToolsSonic's formatter reports lexical warnings (unclosed strings, unbalanced parentheses) but is not a full SQL parser or validator.
Linting checks semantic rules — for example, whether SELECT * is used, whether a JOIN condition exists, whether a DELETE has a WHERE clause. Formatting only changes layout. ToolsSonic focuses on formatting and lexical diagnostics; it does not apply linting rules or claim to catch query logic errors.
The review panel reports: unclosed single-quoted strings, unclosed double-quoted identifiers, unclosed backtick names, unclosed dollar-quoted strings, unclosed block comments, unbalanced parentheses, and empty-input warnings. The stats bar shows statement count, output lines, total tokens, recognized keywords, comments, maximum parenthesis depth, and warning count.
Yes. Select the PostgreSQL dialect hint. This adds RETURNING, ILIKE, MATERIALIZED, LATERAL, JSONB, SERIAL, BIGSERIAL, ARRAY_AGG, STRING_AGG, GENERATE_SERIES, and EXCLUDED to the recognized keyword set so they are formatted and recased correctly alongside standard SQL keywords.
Yes. Select the BigQuery dialect hint. This adds UNNEST, STRUCT, ARRAY_AGG, COUNTIF, APPROX_COUNT_DISTINCT, GENERATE_ARRAY, SAFE_CAST, TIMESTAMP_TRUNC, DATE_TRUNC, PIVOT, UNPIVOT, and other BigQuery-specific keywords to the recognized set.
Yes. Select the Snowflake dialect hint. This adds QUALIFY, SAMPLE, CLONE, UNDROP, FLATTEN, SPLIT_TO_TABLE, ARRAY_AGG, OBJECT_AGG, TO_VARIANT, PARSE_JSON, ARRAY_CONSTRUCT, OBJECT_CONSTRUCT, IFF, IFNULL, ZEROIFNULL, and other Snowflake-specific keywords. QUALIFY (used to filter window function results) and FLATTEN (used to expand semi-structured data) are formatted as major clause breaks for readability.
Yes. Select the Amazon Redshift dialect hint. This adds SORTKEY, DISTKEY, DISTSTYLE, ENCODE, COPY, UNLOAD, CONVERT_TIMEZONE, DATEADD, DATEDIFF, APPROXIMATE, PERCENTILE_CONT, MEDIAN, LISTAGG, REGEXP_COUNT, REGEXP_REPLACE, GETDATE, and other Redshift-specific keywords so they are formatted and recased correctly alongside standard SQL.
Yes. The formatter runs 8 heuristic lint checks on every format pass: (1) SELECT * is flagged as a readability hint, (2) DELETE without WHERE warns that all rows may be deleted, (3) UPDATE without WHERE warns that all rows may be updated, (4) DROP TABLE is flagged as a safety notice, (5) empty consecutive statements (;;) are reported, (6) CASE without a matching END is detected, (7) BEGIN without COMMIT or ROLLBACK is flagged for transaction boundary review, and (8) nesting depth ≥ 4 is flagged as a complexity hint. These are token-level checks — they add advisory messages to the review panel without blocking output or claiming full semantic validation.
Yes. Press Ctrl+Enter (or Cmd+Enter on Mac) to format at any time without clicking the Format SQL button. This shortcut works from both the input editor and anywhere else on the page.
Yes. Use Copy SQL to place the current output on the clipboard, or Download .sql to save it as a local SQL file. Neither action sends the query to a remote service. The download uses a browser Blob URL that is immediately revoked after the download starts.
Yes. The session history (last 8 formatted queries) is stored only in JavaScript memory for the current page session. It is never written to localStorage, sessionStorage, cookies, or a server. Refreshing the page clears it entirely.
Yes. All three cloud data warehouse dialects are supported with dedicated keyword sets. Snowflake SQL with QUALIFY, FLATTEN, ARRAY_CONSTRUCT, and semi-structured extensions is recognized. Amazon Redshift SQL with SORTKEY, DISTKEY, ENCODE, COPY, UNLOAD, and analytical function keywords is recognized. BigQuery SQL with UNNEST, STRUCT, PIVOT, UNPIVOT, ARRAY_AGG, and date-math functions is recognized. Select the appropriate dialect hint before formatting.
What is SQL Formatter?
An SQL Formatter (also called an SQL Beautifier or SQL Pretty Printer) transforms dense, unreadable SQL queries into clean, structured layouts with consistent indentation, keyword casing, clause line breaks, preserved comments, and statement separation — without executing the query, connecting to a database, or uploading your SQL to a third-party service.
SQL is written under pressure: ORMs generate single-line monster queries, copy-pasted snippets have no indentation, legacy scripts mix uppercase and lowercase keywords arbitrarily, and production SQL files contain comments from a dozen different engineers. A good SQL formatter saves hours of manual reading and makes peer review, debugging, and documentation dramatically faster.
ToolsSonic's SQL Formatter is a browser-only readability workspace. It uses a lexical scanner that tokenizes every input character before applying any formatting decision. Single-quoted strings ('value'), double-quoted identifiers ("column"), backtick-quoted names (\table\), dollar-quoted PostgreSQL strings ($$body$$), line comments (-- comment), and block comments (/* note */) are all protected before keywords are recased or clauses are broken. This means a query containing a string like 'SELECT stays inside a string' will never have its embedded text rewritten as a SQL keyword.
Three formatting modes in one tool. Format mode applies indentation, clause breaks, keyword casing, comma layout, AND/OR line placement, blank-line spacing between statements, and hard-wrap targets. Recase Only mode changes keyword casing only — preserving all original whitespace and indentation exactly as written, ideal for normalizing a style convention without reformatting layout. Minify mode strips all whitespace and comments to produce the most compact single-line SQL possible, useful for embedded SQL strings, wire payloads, or log-friendly query serialization.
Ten dialect hints. Generic SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server / T-SQL, Oracle / PL-SQL, BigQuery, Snowflake, and Amazon Redshift each contribute additional vendor-specific keywords to the recognized set. PostgreSQL adds RETURNING, ILIKE, LATERAL, JSONB, and ARRAY_AGG. BigQuery adds UNNEST, STRUCT, PIVOT, UNPIVOT, and COUNTIF. Snowflake adds QUALIFY, FLATTEN, CLONE, UNDROP, IFF, TO_VARIANT, PARSE_JSON, and ARRAY_CONSTRUCT. Redshift adds SORTKEY, DISTKEY, ENCODE, COPY, UNLOAD, CONVERT_TIMEZONE, and APPROXIMATE. Each dialect hint improves casing accuracy and clause detection without claiming complete grammar validation.
Eight heuristic lint checks. Every format pass also runs a set of token-level safety and style advisories: SELECT * is flagged for column-specificity, DELETE without WHERE and UPDATE without WHERE are flagged as potential full-table operations, DROP TABLE is highlighted for production safety review, CASE without END and BEGIN without COMMIT/ROLLBACK are detected as structural warnings, consecutive empty statements are reported, and nesting depth ≥ 4 is flagged as a complexity hint. These are advisory — they add messages to the review panel without blocking output or claiming full semantic validation.
Flexible comma and boolean layout. Choose inline commas (value1, value2, value3), trailing newline commas (comma at end of each line), or leading commas (, value2 on the next line — the style guide used by many senior DBAs and preferred in BigQuery and Snowflake team conventions). AND/OR can remain inline or move to a new line for WHERE clause readability. Blank lines between semicolon-delimited statements can be set to 0, 1, or 2 for visual separation in multi-statement scripts.
Common use cases
- Formatting SELECT, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT queries for peer review
- Formatting CTEs (Common Table Expressions) with WITH and RECURSIVE for readability
- Formatting INSERT INTO, UPDATE SET, DELETE FROM, and MERGE statements
- Formatting CREATE TABLE, ALTER TABLE, DROP INDEX, and other DDL statements
- Recasing SQL keywords from mixed case to UPPERCASE or lowercase without reformatting layout
- Minifying SQL for embedded query strings, API payloads, or log-friendly serialization
- Formatting PostgreSQL-specific SQL with RETURNING, LATERAL, JSONB, and dollar-quoted strings
- Formatting BigQuery SQL with UNNEST, STRUCT, PIVOT, UNPIVOT, and APPROX_COUNT_DISTINCT
- Formatting T-SQL with TOP, MERGE, OUTPUT, NVARCHAR, and IDENTITY
- Formatting a local .sql, .ddl, or .dml file without uploading it to any server
- Reviewing token, keyword, comment, depth, statement, and warning statistics for a SQL script
Why use ToolsSonic's SQL Formatter?
Most free SQL formatters online — SQL-Formatter.com, dpriver.com/Instant SQL Formatter, Atline SQL Formatter — fall into two camps: browser-based tools with a single paste box and no privacy guarantees, or parser-backed tools with so many options they require a manual to operate. ToolsSonic addresses both gaps.
Full string, comment, and identifier protection. The lexical tokenizer handles single quotes, double quotes, backticks, dollar-quoted strings ($$), line comments, and block comments before any formatting decision is made. This means keywords inside strings are never recased, semicolons inside strings never split statements, and comment content is never rewritten. Most free online SQL formatters use regex-based replacement that breaks on edge cases — embedded keywords, escaped quotes, and nested comments.
Three modes, zero upload. Format, Recase Only, and Minify run entirely in your browser tab. Open DevTools → Network and confirm zero outbound requests when formatting. No account required, no query history on any server, no analytics on your SQL text.
Ten dialect hints including Snowflake and Redshift. The addition of Snowflake and Amazon Redshift alongside BigQuery and MariaDB gives ToolsSonic coverage of all four major cloud data warehouse platforms. Snowflake's semi-structured SQL (QUALIFY, FLATTEN, TO_VARIANT, ARRAY_CONSTRUCT, PARSE_JSON) and Redshift's distribution/sort DDL (SORTKEY, DISTKEY, ENCODE) are now correctly recognized and recased.
Eight heuristic lint advisories. Token-level safety hints flag DELETE/UPDATE without WHERE, DROP TABLE, missing CASE END, transaction boundary issues, and deep nesting — without blocking output or requiring a full parse tree. No free browser SQL formatter reviewed includes these safety advisories.
Session history with restore. The last 8 formatted queries are kept in memory for the current page session — restore any previous input instantly without re-pasting. History is never written to localStorage or a server.
Leading comma support. The leading comma style (SQL Server DBAs, BigQuery style guides, many enterprise SQL standards) is fully supported alongside inline and trailing-newline comma layouts. No free online competitor reviewed offers all three modes simultaneously.
SQL Formatting Controls — Quick Reference
| Control | Options | What it does |
|---|---|---|
| Mode | Format / Recase Only / Minify | Format applies full layout; Recase Only changes keyword case without altering whitespace; Minify collapses to single compact line |
| Dialect | Generic, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery | Adds vendor-specific keywords to the recognized set for accurate casing and clause detection |
| Indent | 2 spaces / 4 spaces / Tab | Controls indentation width for nested clauses and subqueries |
| Keywords | UPPERCASE / lowercase / Preserve | Applies to all recognized SQL keywords; leaves strings, identifiers, and unrecognized tokens unchanged |
| Comma | Inline / New line trailing / New line leading | Inline keeps commas at end of current token; trailing puts comma at end of line; leading puts comma at start of next line |
| AND / OR | New line / Inline | New line places AND/OR at the start of their own lines inside WHERE and HAVING; Inline keeps them on the same line as the preceding condition |
| Wrap at | None / 80 / 100 / 120 columns | Wraps output lines at the specified character width; split point is the last space before the limit |
| Blank lines | 0 / 1 / 2 | Inserts blank lines between semicolon-delimited statements for visual separation in multi-statement scripts |
| Preserve comments | On / Off | When on, keeps -- line comments and /* block comments */ in output; when off, strips all comments |
| Split statements | On / Off | When on, each semicolon-delimited statement begins on a new line; semicolons inside strings are protected |
ToolsSonic SQL Formatter vs SQL-Formatter.com vs Instant SQL Formatter
| Feature | ToolsSonic | SQL-Formatter.com | Instant SQL Formatter |
|---|---|---|---|
| Dialects | 8 (incl. BigQuery, MariaDB) | 9 (incl. Snowflake, Redshift) | 20+ (parser-backed) |
| String protection | ✅ Single, double, backtick, $$ | ✅ Partial | ✅ Parser-based |
| Minify mode | ✅ | ✅ | ✅ (compact) |
| Recase Only mode | ✅ | ❌ | ✅ (keep-layout) |
| Leading comma | ✅ | ❌ | ✅ |
| Blank lines between statements | ✅ 0/1/2 | ✅ | ❌ |
| Session history | ✅ 8 entries, in-memory | ✅ 5 entries, localStorage | ❌ |
| Zero upload / no server | ✅ Verified — zero network requests | ✅ Claimed | ❌ Server-based (desktop option) |
| Dark mode | ✅ | ❌ | ❌ |
| Local file input | ✅ .sql/.ddl/.dml | ✅ | ❌ |
| Privacy — no localStorage | ✅ Zero persistence | ❌ Saves settings and history | ❌ Server processes SQL |
Related tools
CSV to SQL INSERT
Editor's choiceConvert CSV to SQL INSERT statements with dialect hints, identifier quoting, NULL and type policies, batching, and row diagnostics — nothing uploaded.
JSON Formatter
Editor's choiceFormat, beautify, minify, and validate JSON locally. Choose indentation, sort keys, preserve Unicode, inspect statistics, and copy or download clean output.
JSON Validator
Editor's choiceValidate JSON online with precise line and column diagnostics, targeted repair hints, structure inspection, and browser-only processing — no upload, no account.
CSV Viewer
Editor's choiceView CSV and TSV files as a fast, searchable, sortable table. Detect delimiters, inspect columns, filter rows, sort mixed data, toggle columns, paginate large previews, and export selected rows locally.
Text Compare
Compare two texts online and instantly see every difference — added lines in green, removed lines in red, and character-level changes highlighted, just like GitHub.