T-SQL Formatter

Paste a SQL Server query to format it with T-SQL syntax rules. The SQL Server (T-SQL) dialect is already selected.

Advertisement

Format SQL Server (T-SQL) queries online

Queries captured from SQL Server Profiler, Extended Events or an Entity Framework log usually arrive as one long line. This T-SQL formatter lays them out clause by clause so joins, filters and sort order can be read at a glance — handy before a code review or when tuning a slow query.

It handles T-SQL specifics such as TOP, [square bracket] identifiers, @variables, schema-qualified names like dbo.Orders and GO batch separators. Formatting happens in your browser, so nothing about your database is uploaded.

Example: a SQL Server query

Before:

select top 10 [o].[Id],[c].[Name],o.Total from dbo.Orders o inner join dbo.Customers c on c.Id=o.CustomerId where o.CreatedAt>=@from and o.Status=@status order by o.Total desc

After formatting:

SELECT
  TOP 10 [o].[Id],
  [c].[Name],
  o.Total
FROM
  dbo.Orders o
  INNER JOIN dbo.Customers c ON c.Id = o.CustomerId
WHERE
  o.CreatedAt >= @from
  AND o.Status = @status
ORDER BY
  o.Total DESC

Frequently asked questions

Does it keep my [bracketed] column names?
Yes. Square-bracket identifiers, @variables and schema prefixes are kept exactly as written. Only whitespace, line breaks and keyword case change.
Can I format a stored procedure?
Yes. Paste the full CREATE PROCEDURE script and every statement in it is formatted. Use GO between batches as you would in SSMS.
Is this the same as formatting in SSMS?
SQL Server Management Studio has no built-in query formatter, so many developers paste queries into an online tool like this one or install an add-in. This page needs no install.
Is my query sent to a server?
No. The formatter runs entirely in your browser, so table names and data never leave your computer.

Related tools