How to Format SQL in SSMS (SQL Server Management Studio)
Published: July 7, 2026 | Updated: July 7, 2026
If you write T-SQL queries in SQL Server Management Studio (SSMS), you have probably wondered how to format SQL in SSMS without copying code to an external tool every time. Fortunately, SSMS includes several built-in formatting features, and you can extend them with third-party add-ins or use a free online SQL formatter for T-SQL.
This guide covers every method to format SQL in SSMS — from built-in keyboard shortcuts to professional formatters — so you can keep your T-SQL clean, readable, and consistent.
1. Built-in SSMS SQL Formatter (Keyboard Shortcuts)
SSMS ships with a basic built-in SQL formatter that handles indentation and keyword capitalization. This is the quickest way to format SQL in SSMS without installing anything.
Default Keyboard Shortcuts
- Ctrl+K, Ctrl+D — Format the entire document (all SQL in the current query window)
- Ctrl+K, Ctrl+F — Format only the selected text (highlight a block of SQL first)
To use these, open a query window in SSMS, write or paste your T-SQL, then press the shortcut. SSMS immediately reformats the keywords to uppercase and adjusts indentation.
How to Customize SSMS Formatting Shortcuts
If the default shortcuts conflict with other tools you use:
- Go to Tools > Options > Environment > Keyboard
- Search for
Edit.FormatDocument or Edit.FormatSelection
- Assign your preferred key combination
Note: The built-in SSMS formatter is intentionally simple. It capitalizes keywords and adds indentation but does not offer options like custom spacing, alignment, or formatting-specific SQL constructs (such as CTEs or window functions) the way a dedicated SQL beautifier does.
2. Third-Party SSMS SQL Formatting Add-Ins
For professional T-SQL formatting with full control over styles, third-party SSMS add-ins are the next step. These tools integrate directly into SSMS and format your SQL with a single click or shortcut.
Popular SSMS SQL Formatting Tools
- ApexSQL Refactor — Free add-in with extensive formatting options, including custom layouts, indentation rules, and keyword casing control
- SQL Complete (Devart) — Paid tool with a rich SQL formatter, code completion, and refactoring features
- Redgate SQL Prompt — Industry-standard SQL formatting and intellisense for SSMS. Offers customizable formatting styles
- Poor Man's T-SQL Formatter — Free, open-source SSMS add-in with basic but reliable T-SQL formatting
Most of these tools add a new toolbar or menu item in SSMS under a "Format SQL" or "Refactor" heading. Once installed, you can format your queries with minimal friction — often with keyboard shortcuts you define.
4. Using an Online SQL Formatter for T-SQL
When you are not running SSMS — for example, you are reading a query in a browser, Slack, or a blog post — a free online SQL formatter is the fastest way to format T-SQL. Our online formatter supports the T-SQL dialect natively.
Format T-SQL Online — Free, No Signup
Paste your T-SQL below, select T-SQL (SQL Server) as the dialect, and format instantly. Zero data leaves your browser.
Open SQL Format Tool →
The online formatter supports all T-SQL features: CTEs (WITH clauses), window functions, MERGE statements, TRY...CATCH blocks, dynamic SQL, and more. Just paste your T-SQL into the input box, select "T-SQL" as the dialect, and the formatter handles the rest.
When to Use an Online Formatter vs. SSMS Built-in
- Use SSMS built-in: When you are already in SSMS and need a quick reformat
- Use a third-party add-in: When you format T-SQL daily and want consistent team styles
- Use an online formatter: When you are not in SSMS, are on another machine, or want to share a clean version of a query with someone
5. Tips for Clean T-SQL Formatting
Regardless of which tool you use to format SQL in SSMS, these best practices keep your queries readable and maintainable.
Use Consistent Keyword Casing
SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY should use the same case throughout your codebase. Upper case for keywords is the industry standard.
Align Columns in SELECT Statements
When you have multiple columns in a SELECT, put each column on its own line with consistent indentation:
SELECT
u.UserID,
u.UserName,
u.Email,
o.OrderID,
o.OrderTotal
FROM dbo.Users u
INNER JOIN dbo.Orders o
ON u.UserID = o.UserID
WHERE o.OrderDate >= '2026-01-01'
AND o.Status = 'Shipped'
ORDER BY o.OrderDate DESC;
Structure CTEs and Subqueries Clearly
CTEs (WITH clauses) should show the structure at a glance. Each CTE on its own line, followed by the main query distinctly separated:
WITH RecentOrders AS (
SELECT
UserID,
COUNT(*) AS OrderCount,
MAX(OrderDate) AS LastOrderDate
FROM dbo.Orders
WHERE OrderDate >= DATEADD(month, -3, GETDATE())
GROUP BY UserID
)
SELECT
u.UserName,
ro.OrderCount,
ro.LastOrderDate
FROM dbo.Users u
INNER JOIN RecentOrders ro
ON u.UserID = ro.UserID
ORDER BY ro.OrderCount DESC;
Pro tip: If you inherit legacy T-SQL that is poorly formatted, paste it into the free online SQL formatter with T-SQL dialect selected. Watch as the entire query transforms into a readable structure.
6. FAQ — Format SQL in SSMS
Can SSMS format SQL automatically?
Yes. SSMS has a built-in formatter accessible via Edit > Advanced > Format Document or using the shortcut Ctrl+K, Ctrl+D to format the whole document, and Ctrl+K, Ctrl+F to format a selected block.
Does SSMS have a SQL beautifier built in?
SSMS includes a basic SQL formatter that handles indentation and keyword capitalization. For more advanced formatting — custom indentation, line breaks, spacing rules — third-party add-ins or online formatters are recommended.
What is the shortcut to format SQL in SSMS?
The default shortcut is Ctrl+K then Ctrl+D (format document) or select text and press Ctrl+K then Ctrl+F (format selection). You can customize these shortcuts under Tools > Options > Environment > Keyboard.
Can I use an online SQL formatter for T-SQL?
Yes. SQLFormat.io supports T-SQL dialect. Simply paste your T-SQL code into the editor, select T-SQL as the dialect, and format instantly — no installation needed.