Skip to content
koducathome

SQL Server Formatter (T-SQL)

Format and beautify T-SQL for Microsoft SQL Server and Azure SQL: [bracketed] names, TOP, CTEs and functions like GETDATE() and ISNULL() — in your browser.

How to use this tool

Steps for using the SQL Formatter.

  1. Paste your SQL Server (T-SQL) query into Input SQL — SQL Server (T-SQL) is already selected under Dialect, so its quoting, parameters and operators are understood.
  2. Pick Keyword case (UPPERCASE, lowercase or Preserve) and Indentation, and open Formatting options for indent style, AND / OR placement and line width.
  3. Choose an Action: Format to beautify, Minify to put it on one line, Validate to check the syntax, or Explain for a plain-English summary.
  4. Copy or download the result. Formatting only changes whitespace and keyword case — the query does the same thing.

Example

TOP with [bracketed] names

T-SQL
select top 10 [o].[Id], [c].[Name] from [dbo].[Orders] o join [dbo].[Customers] c on c.Id = o.CustomerId where o.Total > 100 order by o.Total desc
Formatted
SELECT
  TOP 10 [o].[Id],
  [c].[Name]
FROM
  [dbo].[Orders] o
  JOIN [dbo].[Customers] c ON c.Id = o.CustomerId
WHERE
  o.Total > 100
ORDER BY
  o.Total DESC

Common use cases

  • Tidying queries copied from SSMS, Azure Data Studio or logs before code review.
  • Making stored procedure bodies and views readable before committing them.
  • Comparing two versions of a query after formatting both the same way.
  • Pasting readable T-SQL into tickets and documentation.

What makes T-SQL different to format

SQL Server's dialect, Transact-SQL, quotes identifiers with square brackets — [dbo].[Orders] — so names can contain spaces or clash with keywords. With the SQL Server dialect selected, the formatter treats [...] as one name instead of trying to parse what's inside.

T-SQL also has its own syntax for limiting rows (SELECT TOP 10 rather than LIMIT), schema-qualified names such as dbo.Customers, and built-in functions like GETDATE(), DATEADD() and ISNULL(). The formatter keeps all of these intact and only changes layout and keyword case.

Long queries copied from SQL Server Management Studio, Azure Data Studio or application logs are often one line. Breaking them at SELECT, FROM, JOIN, WHERE and ORDER BY, and indenting CTEs and subqueries, makes the logic reviewable — the CTE example above is the same query, just readable.

Formatting runs in your browser, so connection strings or table names never leave your machine. For other databases, see the MySQL, PostgreSQL and Oracle formatters.

Limitations

  • The formatter doesn't know your database schema — misspelled tables or columns aren't detected.
  • Very large scripts are best split into batches.
  • Comments are kept, but their position may change slightly around reformatted lines.

Frequently asked questions

How do I format SQL in SQL Server Management Studio?

SQL Server Management Studio doesn't include a full query formatter in most versions. Paste the query here with the SQL Server dialect selected, format it, and paste it back.

Does formatting change what my T-SQL does?

No. Only whitespace, line breaks and (if you choose) keyword case change. Identifiers, strings and values are left exactly as written.

Why select the SQL Server dialect instead of Standard SQL?

So T-SQL syntax such as [bracketed] names is understood. Standard SQL can mis-parse brackets and report errors on valid SQL Server code.

Is my query sent to a server?

No. The SQL Server formatter runs entirely in your browser.