Formatting preserves identifiers and aliases. Style suggestions are not database validation. Maximum input: 100,000 characters.

INPUT 0 characters, 0 lines
OUTPUT
Ctrl + Enter

Turning history off also clears saved queries. Shared links contain your SQL; only share queries you intend others to read.

Client-Side Only

SQL formatting happens locally in your browser. Analytics records usage metadata, not SQL text. See our privacy details.

9 Dialects

PostgreSQL, MySQL, SQL Server, BigQuery, SQLite, MariaDB, Redshift, and Snowflake.

Saves Settings

Your indent size, keyword case, and dialect preferences are saved locally between sessions.

Query History

Optionally keeps your last 5 queries in this browser. Turn history off or clear it at any time.

Ctrl+Enter Format
Ctrl+Shift+C Copy
Ctrl+Shift+Backspace Clear
Ctrl+] Indent
? Shortcuts

Free Online SQL Server Formatter

This SQL Server formatter instantly beautifies your T-SQL queries, making them easier to read, debug, and maintain. Simply paste your unformatted query and click Format.

T-SQL Specific Formatting

Our formatter understands SQL Server and T-SQL specific syntax including:

  • Data Types: NVARCHAR, UNIQUEIDENTIFIER, DATETIME2, DATETIMEOFFSET
  • Functions: GETDATE, DATEADD, CONVERT, CAST, ISNULL, COALESCE
  • Query Hints: WITH (NOLOCK), OPTION (RECOMPILE), table hints
  • TOP Clause: SELECT TOP n, TOP n PERCENT, TOP n WITH TIES
  • CTEs: Common Table Expressions with recursive support
  • MERGE: MERGE INTO with WHEN MATCHED/NOT MATCHED
  • OUTPUT: OUTPUT clause for INSERT, UPDATE, DELETE

Why Format T-SQL Queries?

SQL Server is widely used in enterprise environments where code quality matters. Clean, formatted queries help with:

  • Stored procedure development and maintenance
  • Query performance tuning with execution plans
  • Database migration projects
  • Team collaboration and code reviews

Worked examples

TOP with a table hint

Table hints attach to the table, not the query. Formatting keeps WITH (NOLOCK) beside the table it applies to so the scope stays clear.

Before

select top 100 u.id,u.name,convert(varchar,u.created_at,120) as signup from dbo.users u with (nolock) inner join dbo.orders o on u.id=o.user_id where u.status='active' and o.order_date>dateadd(day,-30,getdate()) order by o.order_date desc

After

SELECT
  TOP 100 u.id,
  u.name,
  convert(varchar, u.created_at, 120) AS signup
FROM
  dbo.users u
WITH
  (nolock)
  INNER JOIN dbo.orders o ON u.id = o.user_id
WHERE
  u.status = 'active'
  AND o.order_date > dateadd(DAY, -30, getdate())
ORDER BY
  o.order_date DESC

MERGE with an OUTPUT clause

MERGE is one statement with several branches. Each WHEN and the OUTPUT clause land on their own line, which is where mistakes in MERGE usually hide.

Before

merge into dbo.target as t using dbo.source as s on t.id=s.id when matched and t.amount<>s.amount then update set t.amount=s.amount when not matched by target then insert (id,amount) values (s.id,s.amount) output inserted.id,inserted.amount;

After

MERGE INTO
  dbo.target AS t using dbo.source AS s ON t.id = s.id
WHEN MATCHED
  AND t.amount <> s.amount THEN
UPDATE SET
  t.amount = s.amount
WHEN NOT MATCHED BY TARGET THEN
INSERT
  (id, amount)
VALUES
  (s.id, s.amount) OUTPUT inserted.id,
  inserted.amount;

Bracketed identifiers and a windowed CTE

Bracketed names keep their spacing and casing, and the CTE body is indented away from the outer query.

Before

with ranked as (select [User Id],[Order Total],row_number() over (partition by [User Id] order by [Order Total] desc) as rn from dbo.[Order History]) select * from ranked where rn=1

After

WITH
  ranked AS (
    SELECT
      [User Id],
      [Order Total],
      row_number() OVER (
        PARTITION BY
          [User Id]
        ORDER BY
          [Order Total] DESC
      ) AS rn
    FROM
      dbo.[Order History]
  )
SELECT
  *
FROM
  ranked
WHERE
  rn = 1

Other SQL Dialects

Need to format SQL for other databases? Try our formatters for PostgreSQL, MySQL, BigQuery, or SQLite.

PostgreSQL MySQL SQL Server BigQuery SQLite MariaDB Redshift Snowflake