SQL Server Formatter & T-SQL Beautifier

Format and beautify T-SQL for SQL Server in your browser, with square brackets, @variables and GO batch separators left in place.

Client-side only, nothing leaves your browser

Formatted SQL will appear here...

Formatting T-SQL

T-SQL scripts mix square-bracket identifiers, @variables, TOP and GO batch separators, and a generic SQL formatter often mangles one of them. This page uses the Transact-SQL dialect of sql-formatter, so brackets stay attached to names, @parameters are read as single tokens and each GO stays on its own line between batches. It is handy when you are away from SSMS or need to clean up a query pasted from a ticket or a log.

Supported Features

  • Queries: SELECT, INSERT, UPDATE, DELETE, MERGE
  • DDL: CREATE TABLE, ALTER, CREATE INDEX, CREATE VIEW
  • T-SQL syntax: TOP, square brackets, @variables, GO batches
  • Advanced: CTEs, window functions, CROSS APPLY, OUTPUT

Formatting Styles

StyleDescriptionExample
StandardKeywords on new lines, indented clausesSELECT
col
FROM
table
Tabular LeftKeywords left-aligned in columnSELECT col
FROM table
WHERE x = 1
Tabular RightKeywords right-aligned in columnSELECT col
  FROM table
 WHERE x = 1

Frequently asked questions

Does SQL Server Management Studio have a formatter?
SSMS 22.7 and later include Format SQL, which you run from the right-click menu, from Edit > Advanced, or with Ctrl+K, Ctrl+Q. It is built on Microsoft's open-source ScriptDOM parser and can format on save, with options read from Tools > Options or an .editorconfig file. Earlier versions such as SSMS 20 and 21 have no formatter, which is why add-ins like Poor Man's T-SQL Formatter are popular.
What is Poor Man's T-SQL Formatter?
Poor Man's T-SQL Formatter is a free, open-source formatter by Tao Klerks, hosted on GitHub. It ships as an SSMS add-in, a Visual Studio extension, a Notepad++ plugin, a command-line bulk formatter and a JavaScript library. Its README warns that settings may not carry over across major SSMS and Visual Studio upgrades, so check it supports your SSMS version before installing.
How do I format T-SQL in VS Code?
Microsoft's MSSQL extension for VS Code has its own SQL formatter, added as a preview in version 1.45 and generally available from 1.46. Run Format Document with Shift+Alt+F (Shift+Option+F on macOS), and set keyword casing and other options under Mssql > Format in Settings. Turn on editor.formatOnSave to format every time you save.
What are T-SQL formatting best practices?
Write keywords in uppercase, start each major clause (SELECT, FROM, WHERE, GROUP BY) on a new line and give each column its own line in long lists. Schema-qualify objects as dbo.Orders, end statements with a semicolon and keep GO on its own line. Use square brackets only where a name needs them, such as a reserved word or a name with spaces.
How do I format a date in T-SQL?
FORMAT(GETDATE(), 'yyyy-MM-dd') takes .NET format strings and has been available since SQL Server 2012. CONVERT(varchar(10), GETDATE(), 23) gives the same yyyy-mm-dd result with a numeric style code and runs faster over large result sets. Use CONVERT in queries that touch many rows and FORMAT when you need culture-aware output.
SQL Server

Want 1bench for SQL Server?

1bench doesn't connect to SQL Server yet. Ask for it and we'll let you know as soon as early access opens.

Request Early Access