SQL formatter input
Choose a review style, then adjust visible controls when the query needs a team-specific convention.
Pick the closest database syntax before formatting.
Paste one query or a multi-statement script; comments and string literals are preserved by the formatter engine.
{{ fileStatus }}
Uppercase is common for review; Preserve keeps source keyword casing where possible.
Use 2 or 4 for most database review workflows.
spaces
Leave Preserve unless your team standardizes data-type casing.
Preserve is safest for vendor-specific and user-defined functions.
Before makes scan paths clear in WHERE and HAVING clauses.
Use 1 for compact scripts or 2 for review documents.
line(s)
Lower values break long predicates sooner.
chars
Leave off unless the destination repository requires tabs.
{{ use_tabs ? 'On' : 'Off' }}
Off is easier to review; on can match compact legacy style.
{{ dense_operators ? 'On' : 'Off' }}
Off keeps the semicolon at the end of the statement line.
{{ newline_before_semicolon ? 'On' : 'Off' }}
{{ formattedSql }}
# Statement Input Output Review note Copy
{{ row.index }} {{ row.type }} {{ row.inputLabel }} {{ row.outputLabel }} {{ row.note }}
Check Status Detail Copy
{{ row.check }} {{ row.status }} {{ row.detail }}

        
Customize
Advanced
:

Introduction

SQL is easier to judge when its clauses, joins, filters, and statement boundaries are visible before anyone runs it. A dense one-line query can hide a missing join condition, a filter that belongs after grouping, or a second statement pasted into the same script. Formatting does not prove the SQL is correct, but it gives reviewers a shape they can inspect.

Readable layout matters in pull requests, incident fixes, migration scripts, report queries, warehouse jobs, and support handoffs. In those settings, the first review pass is usually practical rather than theoretical: which tables are touched, how rows are filtered, where grouping happens, whether a data-changing statement is present, and whether a semicolon marks the intended end of a command.

The harder part is that SQL is a family of related languages, not one universal grammar. PostgreSQL, MySQL, SQL Server, Oracle, SQLite, BigQuery, Snowflake, Redshift, DuckDB, Spark SQL, Trino, and DB2 share many keywords, but their quoting rules, procedural blocks, data types, functions, and operators can differ. A layout that is readable for one engine can still need database-specific review before execution.

Keyword
A grammar word such as SELECT, UPDATE, JOIN, WHERE, or ORDER BY.
Identifier
A database object name, such as a table, column, schema, alias, function, or procedure name.
Literal
A value written into the SQL text, such as a string, number, date, interval, or vendor-specific constant.
Terminator
Usually a semicolon that marks the end of a statement when it appears outside quotes and comments.
Review questions helped by SQL formatting
Review question Layout helps reveal Still needs database review
What rows are read? FROM, JOIN, WHERE, and join predicates become easier to scan. Object existence, permissions, indexes, and query plan quality.
What rows can change? UPDATE, DELETE, INSERT, and transaction boundaries stand out. Locking, rollback strategy, affected-row checks, and environment safeguards.
Where does grouping happen? GROUP BY, HAVING, aggregate functions, and ordering get separate visual space. Business correctness of the aggregation and engine-specific function behavior.
How many commands are present? Statement terminators and multi-statement script boundaries are easier to count. Procedural blocks, migration-runner parsing, and vendor-specific terminator rules.
SQL formatting from compact text to reviewable structure A compact SQL statement is separated into tokens, protected quoted regions, clauses, and a reviewable formatted query. Compact SQL select c.id,count(*) from customers c join orders o on o.customer_id=c.id where o.status='paid' Formatting tokens quotes clauses Review shape SELECT c.id, COUNT(*) FROM customers c JOIN orders o

A formatter can make SQL easier to compare, but it cannot prove that the SQL is correct. A well-spaced query can still point at the wrong table, skip a tenant filter, rely on a missing index, call a vendor-only function, or change more data than intended. Formatting belongs early in the review chain, before database validation, query-plan checks, test data, permissions review, and transaction planning.

The safest habit is to keep the original script under version control or in the database tool that will execute it, then use the formatted copy for inspection. Once the text is readable, compare the statement count, inspect joins and filters, check dialect-specific syntax, and test important SQL in the destination database environment.

How to Use This Tool:

  1. Choose a formatting profile. Review readability is a good default, while Wide indentation, Lowercase keywords, and Custom match different team styles.
  2. Select the closest SQL dialect before reading the result. The dialect choice affects vendor syntax such as PostgreSQL casts, MySQL backticks, SQL Server brackets, Oracle PL/SQL blocks, and warehouse SQL variants.
  3. Paste SQL into the editor, load the sample, browse for one SQL or text file, or drop a local file onto the text area. File reading happens in the browser after the page loads.
  4. Set Keyword case and Indent width. Open Advanced when you need data type case, function case, logical operator line breaks, blank lines between statements, expression width, tabs, dense operators, or semicolon placement.
  5. Read the summary badges before copying. They show the selected dialect, profile, indentation style, statement count, input size, output size, and caveat count.
  6. Open Statement Ledger to confirm each statement type, input length, output length, and review note. This is useful for migrations and multi-statement scripts.
  7. Open Formatter Audit or JSON when you need evidence of settings, footprint, caveats, and generated output alongside the formatted SQL.

Use Copy SQL or Download SQL for the formatted query. The ledger and audit tables can be copied or downloaded as CSV, and they can also be exported as DOCX when the shared document export feature is available.

Interpreting Results:

The formatted output is strongest when the summary says SQL Formatted Locally, the caveat count is zero, the selected dialect matches the database family, and the statement count matches the script you intended to format. A clean summary means the formatting pass completed without tool-level warnings. It does not mean the SQL has been executed or proven safe.

SQL formatter result signals
Signal Meaning What to check next
SQL Formatted Locally The main formatting pass completed in the browser. Compare statement count, joins, filters, and terminators before using the result elsewhere.
Formatted with Caveats Output exists, but at least one warning or review note needs attention. Read the warning area, ledger rows, and audit details before copying.
Best-Effort SQL Preview The main formatting pass could not complete, so a conservative clause preview was produced. Repair the SQL or choose a closer dialect, then rerun the formatting pass.
Parentheses need review A statement has unmatched or early-closing parentheses outside quoted text and comments. Fix grouping before trusting the layout or running the statement.
No trailing semicolon detected The statement did not end with a semicolon after trimming whitespace. Decide whether your console, migration runner, or batch script requires explicit terminators.

The Statement Ledger is especially helpful when the source contains several commands. If the ledger count surprises you, look for a semicolon inside quoted text, an unfinished block, a copied comment, or a missing terminator between statements.

Technical Details:

SQL formatting is a token-preserving transformation. Whitespace, line breaks, indentation, and selected casing can change, while string literals, comments, quoted identifiers, and expression order should keep their meaning. The main technical challenge is separating SQL grammar from text that only looks like SQL because it appears inside a string or comment.

Statement boundaries need special care. A semicolon normally ends a command, but a semicolon inside a quoted string, a line comment, a block comment, a backtick-quoted identifier, or a bracket-delimited identifier is part of that protected region. Splitting a script at the wrong semicolon can make a valid migration or stored routine look broken.

Transformation Core

SQL formatting transformation stages
Stage Rule Review boundary
Dialect choice Read syntax using the closest available database family or warehouse variant. Only the target database can confirm final syntax validity.
Protected text Keep string literals, comments, quoted identifiers, backtick names, and bracketed names intact. Formatting should not change literal values, comments, or quoted object names.
Statement split Separate statements at semicolons found outside protected text. Procedural blocks and vendor-specific scripts may still need database-aware review.
Clause layout Break major clauses, joins, unions, grouping, ordering, and selected logical operators onto reviewable lines. Line breaks expose structure but do not validate joins, filters, or execution plans.
Style shaping Apply keyword case, optional data type case, optional function case, indentation, operator spacing, and semicolon placement. Style consistency helps review but does not change database permissions or data impact.
Review notes Report statement count, source and output footprint, parser path, settings, and caveats. Notes flag review needs; they are not a replacement for execution tests.

Dialect and Syntax Boundaries

Formatting rules are safest when they respect the way each database treats identifiers, quotes, blocks, and terminators. The same visual character can have different meaning across engines. Double quotes identify PostgreSQL identifiers, while MySQL may treat them as string quotes unless a server mode changes that behavior. SQL Server bracketed names and Oracle PL/SQL blocks add more cases where generic layout can be misleading.

Dialect features that affect SQL formatting
Syntax area Typical pattern Formatting risk
Keywords and identifiers Keywords carry grammar meaning, while identifiers name tables, columns, aliases, schemas, and routines. Changing keyword case is usually cosmetic, but quoted identifier spelling and case may be significant.
PostgreSQL names Unquoted names fold to lower case, and double-quoted identifiers preserve case and spelling. Do not remove quotes just because the formatted query looks cleaner without them.
MySQL names Backticks quote identifiers, and server mode can affect how double quotes are interpreted. A layout that reads well in one mode may be invalid or misleading in another.
SQL Server names Delimited identifiers can use brackets, and regular identifiers follow Transact-SQL naming rules. Bracketed names should stay intact when surrounding clauses move to new lines.
PL/SQL blocks DECLARE, BEGIN, EXCEPTION, and END divide block sections. Procedural blocks need engine-aware testing after readability cleanup.

Privacy and Accuracy Notes:

The formatting work runs in the browser once the page and its formatter code have loaded. Pasted SQL and files selected through browse or drag-and-drop are read into the local editor. Avoid pasting secrets, credentials, production customer data, or unreleased schema details unless your environment policy allows that use.

A formatter can warn about caveats such as parser fallback, procedural SQL, large source text, missing semicolons, or parenthesis balance. It does not connect to your database, check whether objects exist, inspect permissions, validate transactions, estimate query plans, or guarantee that a statement is safe to run.

Large scripts can take longer to format on smaller devices. When a script is sensitive, long, or procedural, use the formatted result as a review copy and keep the original SQL under version control or in the database tool that will execute it.

Worked Examples:

Reviewing a reporting query

A reviewer pastes a PostgreSQL-style query with a common table expression, joins, a date filter, grouping, and ordering. With uppercase keywords and two-space indentation, the output separates WITH, SELECT, FROM, JOIN, WHERE, GROUP BY, and ORDER BY, making missing predicates and join conditions easier to spot.

Preparing a migration note

A migration draft contains CREATE TABLE, INSERT, and UPDATE statements separated by semicolons. The summary should show three statements, and the ledger should list each one separately before the reviewer copies the formatted SQL into a change request.

Checking a procedural warning

A SQL Server script uses variables and TRY/CATCH blocks. The SQL can still be formatted for readability, but procedural caveats should stay visible in the audit. Test the final script in SQL Server tooling before running it against real data.

Recovering from a fallback preview

A pasted statement with an unfinished nested condition can produce a best-effort preview and a parenthesis note. Fix the missing parenthesis in the source, then confirm the summary returns to the main formatting path before copying the final output.

FAQ:

Does formatting change what my SQL does?

It should change layout and selected casing only. Still compare the result with the original when a caveat appears, especially for procedural SQL, unusual quoting, or vendor-specific syntax.

Which dialect should I choose?

Choose the closest engine family for the query: Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server T-SQL, Oracle PL/SQL, BigQuery, Snowflake, Redshift, DuckDB, Spark SQL, Trino or Presto, or IBM DB2.

What does fallback preview mean?

The main formatting pass could not complete, so a conservative clause layout was shown for review. Treat it as a preview, repair the SQL or dialect choice, and validate the corrected statement in the destination database.

Why does the ledger mention semicolons?

The ledger checks whether each detected statement ends with a semicolon after trimming whitespace. Some consoles tolerate missing terminators, but migration runners and batch scripts often expect them.

Is formatting the same as validating a query?

No. Formatting does not confirm schema names, permissions, data impact, transaction safety, or query plans. It prepares SQL text for human review.

Glossary:

Clause
A structural part of a statement, such as SELECT, FROM, WHERE, GROUP BY, or ORDER BY.
Dialect
The SQL variant used by a database engine or warehouse, such as PostgreSQL, MySQL, SQL Server T-SQL, Oracle PL/SQL, BigQuery, or Snowflake.
Identifier
A name for a table, column, alias, schema, function, procedure, or other database object.
Statement
A complete SQL command or command-like block, often separated from the next statement by a semicolon.
Protected text
Quoted strings, comments, or delimited identifiers that formatting should preserve while changing layout around them.
Procedural SQL
SQL mixed with variables, blocks, stored procedures, functions, triggers, exception handling, or other programming-language features.

References: