Formatting SQL Server with SQLinForm

T-SQL is a powerful and pragmatic dialect with a long history. Many SQLinForm users work with SQL Server in enterprise environments, and formatting T-SQL correctly has its own set of challenges.


Challenges Formatting T-SQL

Optional semicolons

T-SQL has historically treated semicolons as optional statement terminators. This means the formatter cannot rely on semicolons to detect statement boundaries. In practice, many T-SQL scripts use semicolons only before CTEs (required) and inconsistently elsewhere. The formatter must infer statement boundaries from keyword patterns instead.

DDL without semicolons inside IF blocks

A very common T-SQL pattern involves DDL statements inside IF blocks without semicolons. For example: IF OBJECT_ID(‚tempdb..#tmp‘) IS NOT NULL followed by DROP TABLE #tmp with no semicolon. The formatter must recognize that DROP TABLE is a complete statement based on what follows it, not on a terminating character.

IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
    DROP TABLE #tmp

CREATE TABLE #tmp (id INT, name NVARCHAR(100))

ELSE IF vs. ELSE followed by IF

T-SQL does not have a true ELSE IF keyword — it is ELSE followed by a standalone IF. Formatting this correctly requires recognizing the pattern and keeping ELSE and IF on the same line to produce readable code, rather than placing the IF on a new indented line as if it were a nested block.

BULK INSERT and multi-part options

BULK INSERT has a WITH clause containing many options separated by commas inside parentheses. The formatting must handle the option list clearly while preserving the logical grouping of a statement that looks like DML but behaves more like a utility command.

Dynamic SQL with EXEC and sp_executesql

Dynamic SQL is heavily used in T-SQL. Both EXEC(‚…‘) and sp_executesql N’…‘, @params are common patterns. Like Oracle’s EXECUTE IMMEDIATE, the inner SQL string cannot be reformatted, and the formatter must handle multi-line string concatenation gracefully.

Temporary tables and table variables

T-SQL makes heavy use of temporary tables (#tmp, ##global) and table variables (@table). These appear in DDL-like CREATE TABLE statements within procedures and scripts. Recognizing them as temporary constructs and formatting their column definitions correctly requires the same care as a permanent table definition.


About SQLinForm: SQLinForm is a SQL formatter supporting 25+ database dialects with 200+ formatting options — available for VS Code, SSMS, JetBrains, Notepad++, DBeaver, and as an online formatter. Your SQL never leaves your machine.