# T-SQL Formatter

Format T-SQL for SQL Server and Azure SQL with rules for [bracket] identifiers, N'' Unicode strings, #temp tables, @variables and GO batch separators. CROSS APPLY and OUTER APPLY start new lines, OUTPUT and FOR JSON are kept as clauses and BEGIN TRANSACTION never opens a block by mistake. Unclosed strings and parentheses are reported with line and column for database developers.

## Frequently asked questions

### Which T-SQL syntax is understood?

Identifiers in [square brackets] with ]] escapes or double quotes, N'' Unicode strings, #temp and ##global temporary tables, @variables and @@ system functions are recognized. Static method calls such as geography::Point stay intact too.

### How are GO batch separators handled?

A line that contains only GO, optionally with a repeat count such as GO 5, ends a batch. It stays on its own line and each batch is formatted separately.

### Which T-SQL clauses are supported?

CROSS APPLY and OUTER APPLY start new lines like joins. OUTPUT, OPTION, FOR XML and FOR JSON are kept as their own clauses next to the standard ones.

### Can it format stored procedures?

Yes. BEGIN and END blocks, BEGIN TRY and BEGIN CATCH, IF and ELSE, and WHILE loops are indented. BEGIN TRANSACTION and BEGIN TRAN are treated as statements, not as the start of a block.

### Does it support MERGE?

Yes. WHEN MATCHED, WHEN NOT MATCHED BY TARGET and WHEN NOT MATCHED BY SOURCE branches start new lines.

### Are comments kept?

Yes. -- line comments and /* block comments */ stay in place. Multi-line block comments are re-indented to their new position.

### Does it change keyword case?

No. Keywords and identifiers keep the case you wrote. Only whitespace and line breaks change.

### Which errors are detected?

Unclosed strings, bracket or quoted identifiers and block comments, and unbalanced parentheses, each with line and column. The tool does not connect to SQL Server or validate object names.

### How large can the input be?

Up to 1 MB per request and 128 KB per statement or batch. Statements are separated by blank lines.

### Can I choose the indentation, and is my SQL stored?

You can use 2 or 4 spaces or tabs. Your script is formatted in memory only and never saved.

Your ad here?

[Email us](mailto:hi@dennn.is?subject=Advertising%20on%20OneClick%20Pro)

[Ad The agent-ready plugin suite for WordPress.](https://sleekwp.com/?ref=oneclickpro)
