SQL Server (T-SQL) Formatter
Format SQL Server (T-SQL) queries with consistent indentation and keyword case. Free, and runs entirely in your browser — nothing is uploaded.
About SQL Formatter
A query that arrives as one long line is not readable, and the queries that most need reading are exactly the ones that arrive that way: pulled out of a log, copied from an ORM's debug output, or pasted from a colleague who wrote it in a single sitting. This puts each clause on its own line and indents the joins and conditions underneath.
SQL is not one language, and the places the dialects differ are the places a careless formatter destroys a query. MySQL quotes an identifier with backticks, SQL Server with brackets, and everything else with double quotes — which in PostgreSQL means an identifier and in MySQL means a string. MySQL also treats # as a comment where other dialects read it as something else, and PostgreSQL has dollar-quoted blocks that wrap whole function bodies containing semicolons and quotes of their own.
So the query is tokenised first, with every string, identifier, comment and dollar-quoted block kept whole, and only then laid out. A token that was never split cannot be mangled, which matters far more than the prettiness of the result. Nothing is executed and nothing is validated — it lays out the text you give it, which is what makes it usable on a query that does not run.
Where it helps
- Knows which characters quote an identifier in each dialect, so a name with a space or a keyword in it survives formatting.
- Keeps strings, comments and PostgreSQL dollar-quoted blocks whole, because whitespace inside them is data.
- Puts each clause on its own line and indents joins and boolean conditions under the clause they belong to.
- Upper-cases keywords on request, which is the convention nearly every codebase follows.
- Formats a query that does not parse or does not run, which is when formatting is most needed.
- Runs in the browser, so a query carrying real table names and filters is not sent anywhere.
Limits
- It is a formatter, not a parser: it will not tell you a query is invalid, and it cannot reflow something it has misread.
- Very long expressions and subqueries are indented but not wrapped to a column width.
- Dialect-specific hints and procedural blocks — PL/pgSQL, T-SQL control flow — are laid out by the same clause rules and may not match house style.
- Nothing is executed and no schema is consulted, so it cannot say whether the query is correct, only how it reads.
Frequently asked questions
Does the dialect really matter?
For the layout, rarely. For not breaking the query, yes: the three families quote identifiers differently, and a formatter that reads a MySQL backtick as an ordinary character will split a table name with a space in it into two tokens. Choosing the dialect is how you avoid that.
Will it change what my query does?
It should not — only whitespace between tokens changes, and everything quoted is preserved exactly. The one thing worth checking is a query that was already invalid, where a formatter has no correct answer to give.
Can it format a whole migration file?
Several statements separated by semicolons are handled, each starting a fresh block. PostgreSQL function bodies in dollar quotes are kept intact rather than reformatted, since their contents are a different language.
Related tools
- SQL Minifier — Collapse formatted SQL into compact text
- Structure Formatter — Pretty-print JSON, XML, YAML, TOML, TOON or HCL with a chosen indent
- JavaScript Formatter — Re-indent JavaScript and TypeScript source
- Log Analyzer — Summarise a log: rates, errors, slowest paths and busiest clients
- HTML Formatter — Indent and tidy HTML markup
- CSS Formatter — Format stylesheets with consistent indentation
More Web Development tools
- HTML Formatter — Indent and tidy HTML markup
- CSS Formatter — Format stylesheets with consistent indentation
- JavaScript Formatter — Re-indent JavaScript and TypeScript source
- SCSS/SASS Formatter — Format SCSS syntax and nested rules
- TypeScript Formatter — Format TypeScript source code
- SQL Formatter — Format SQL statements with dialect selection
- SQL Minifier — Collapse formatted SQL into compact text
- CSS Unit Converter — px, rem, em, percentages and viewport units, with a preview
- Query String Parser and Builder — Convert query strings into editable key-value data
- CSP Generator — Build a Content-Security-Policy, or check one, and write it for your server or framework
- CORS Generator — Write CORS configuration for nginx, Express, Go, Django, ASP.NET, Spring and more, and test an origin against it
- cURL Builder — Build an HTTP request and get it as curl, JavaScript, TypeScript, Go, Python, PHP, C#, Java and more
- Minifier — Shrink CSS, HTML or JavaScript
- Flexbox Playground — Try every flex property and read the CSS back
- CSS Grid Playground — Build a grid template and see the tracks it makes
- Responsive Viewport Tester — Render your markup at phone, tablet and desktop widths
- SVG Path Viewer — Draw path data and read back what it contains
- SVG to CSS Converter — Turn an SVG into a data URI for CSS or an img tag
- OAuth 2.0 / OIDC Helper — PKCE verifiers and challenges, state, nonce, and checking what came back
- Regex Tester — Test patterns, inspect groups and preview replacements
- User-Agent Parser — Identify the browser, engine, operating system and device behind a User-Agent string
- HTTP Status Codes — Look up what a status code means, when to send it, and whether it is cached or safe to retry
- HTML to JSX — Convert HTML and SVG markup into JSX for React, with styles, attributes and whitespace handled
- Semver Checker — Test versions against npm ranges, sort them by precedence, and see what each bump produces
- Cookie Parser and Builder — Read Set-Cookie and Cookie headers, check them against browser rules, and write one for your framework