Transact-SQL query beautifier

Format SQL Server queries without uploading them

The SQL Server / T-SQL profile loads automatically. Control indentation, keyword case, expression width, logical-operator breaks, and statement spacing before a disposable local worker formats the text.

Loading the T-SQL formatter…

Enable JavaScript to format Transact-SQL locally. SQL Server syntax and review guidance remains readable below.

Keep formatting reversible

How to format a SQL Server query

  1. 1

    Keep the original T-SQL

    Start from version-controlled source or save an untouched copy. Queries can contain sensitive object names and filters even when no row data is present.

  2. 2

    Use the T-SQL profile

    Select SQL Server / T-SQL because that is the execution target. The formatter then recognizes SQL Server vocabulary and token conventions instead of trying to translate them.

  3. 3

    Diff and test on the target

    Review bracket identifiers, variables, hints, comments, strings, batches, and every filter. Then parse and test with the exact SQL Server version, compatibility level, database, and permissions.

T-SQL has its own lexical edges

Why SQL Server needs a Transact-SQL formatter

Transact-SQL extends SQL with variables, procedural control flow, system functions, temporary objects, table and query hints, error handling, batch-oriented tooling, and SQL Server-specific DDL and DML. A generic formatter may recognize the main clauses but misread punctuation or place a vendor extension as though it were an identifier.

Square brackets delimit identifiers such as [Order] or names containing spaces. Double-quoted identifier behavior depends on QUOTED_IDENTIFIER. Variables generally begin with @, temporary object names can begin with #, and global temporary objects with ##. Those characters are not generic decoration and must remain attached to the intended token.

Unicode character strings commonly use an N prefix. SQL Server also supports multipart names and specific conventions for system and user-defined objects. This tool can change recognized keyword case but keeps function, type, identifier, and quoted text spelling unchanged. That is safer for user-defined functions and case-sensitive collations, but it is still necessary to inspect the diff.

Identifiers
Square brackets commonly delimit names; double quotes depend on settings.
Variables
Local variables and parameters commonly begin with @.
Temporary objects
Names beginning with # or ## have session scope behavior.
Compatibility
Grammar and behavior depend on product version and database compatibility level.

Do not translate while formatting

TOP, OFFSET/FETCH, hints, and T-SQL structure

TOP expressions

TOP belongs near SELECT and can use parentheses, percentages, and ties. A formatter may expose its structure but must not replace it with another dialect's LIMIT.

OFFSET and FETCH

SQL Server offset pagination follows ORDER BY with row counts and an optional next-page count. Layout cannot prove that the ordering is deterministic.

Table hints

Hints such as WITH (...) can affect locking, access paths, and consistency. They must stay with the table reference and receive expert review.

Query hints

OPTION (...) appears at a query boundary. Moving or dropping a hint is a semantic change, not beautification.

Client tooling adds another layer

GO batches, stored procedures, and templates

GO is recognized as a batch separator by tools such as SQL Server Management Studio and sqlcmd. It is not a Transact-SQL statement sent to the database engine like SELECT. A formatter focused on SQL tokens may preserve a familiar GO line without understanding every client rule, repeat count, or surrounding deployment tool.

Stored procedures, functions, triggers, dynamic SQL, TRY/CATCH blocks, cursor operations, and control flow create a broader formatting problem than a single query. Stored procedures and custom-delimiter scripts, including MySQL DELIMITER directives, are not supported here; use SQL Server- and client-aware tooling for routines and deployment scripts.

SQL projects and deployment pipelines may add SQLCMD variables, preprocessor directives, migration annotations, or template syntax. Format with a tool that knows that outer layer, or format a representative rendered artifact. Never delete unfamiliar markers simply because they produce an unattractive formatter result.

GO is a client command

Review batch separators in the context of SSMS, sqlcmd, Azure Data Studio, a database project, migration runner, or whichever client will consume the script. Server-side grammar alone is not enough.

Microsoft documentation for GO →

No connection string required

Private T-SQL formatting in a browser worker

No SQL Server session

The page has no instance, database, login, access token, connection string, catalog, transaction, or query window. It cannot execute the text.

No formatter upload

Text goes only to a worker created by the page. It is not submitted to a query service, proxy, telemetry endpoint, or remote formatter.

Bounded resource use

Input is capped at 50,000 characters, a warning appears at 25,000, the worker stops after 2 seconds, and output beyond 200,000 characters is discarded.

Explicit copy or file

Only your button press copies the result or downloads a local .sql file. Clipboard tools, files, extensions, and device policies remain outside this page.

Pretty T-SQL can still be wrong

Formatting vs SQL Server validation and execution

EvidenceWhat it tells youWhat remains unknown
Formatted outputA readable layout for tokens recognized by this formatter version.Whether SQL Server accepts it or the operation is safe.
Target parserSyntax acceptance under a product version and compatibility context.Objects, permissions, results, side effects, and performance in every case.
Estimated planA plan based on available catalog, statistics, and parameter assumptions.Exact runtime under production concurrency and data.
Controlled testsExpected rows and side effects for representative inputs and permissions.Every future schema, statistic, workload, or operational change.

Questions answered

SQL Server formatter FAQ

Does this T-SQL formatter connect to SQL Server?

No. It formats text locally and has no server, database, credentials, schema, compatibility level, session settings, plan cache, or execution connection.

Does it preserve bracketed identifiers and variables?

The T-SQL profile recognizes square-bracket identifiers, at-sign variables, temporary object names, and SQL Server vocabulary. Review every automated rewrite because settings, extensions, client commands, and new syntax can affect tokenization.

Is GO a Transact-SQL statement?

No. GO is a batch separator recognized by client tools such as SSMS and sqlcmd, not a Transact-SQL statement sent to the server. Scripts with batches need client-aware review.

Does successful formatting validate T-SQL?

No. Validate syntax, objects, types, compatibility level, permissions, row-level behavior, plans, and results with the intended SQL Server environment and application tests.

Can the formatter convert LIMIT to TOP?

No. That would be dialect translation and can require semantic decisions. This page formats existing T-SQL; it does not convert MySQL, PostgreSQL, BigQuery, or another dialect into SQL Server syntax.

Can I format a stored procedure?

No. Stored procedures and custom-delimiter scripts, including scripts using MySQL's DELIMITER client directive, are not supported. Use SQL Server- and client-aware tooling for routines and deployment scripts, and keep the original unchanged.

Why does a large script stop after two seconds?

Pathological formatting can consume significant memory. LiveParse terminates its disposable worker to protect the tab. Split scripts only at safe batch or statement boundaries and preserve dependencies and transactional meaning.