Format a SQL Server Query Online
Turn a single-line T-SQL statement into a readable block, with clauses and joins on their own lines and CASE expressions indented. Minify reverses it when you need the query back on one line.
SQL Formatter
LOCAL · Browser-OnlyFormat and beautify SQL queries with proper indentation
Quick Start
- 1Paste your T-SQL statement into the editor
- 2Pick uppercase, lowercase, or preserved keywords
- 3Set comma placement and indent width
- 4Click Format to rewrite the query in place, then copy it
What This Tool Does
T-SQL usually arrives as one long line out of a profiler or an application log. Formatting breaks it apart: SELECT, FROM, WHERE, GROUP BY, ORDER BY, INSERT INTO, UPDATE, SET and DELETE FROM each start a line, every join form gets its own line, and WHEN, THEN, ELSE and END are indented so a long CASE expression reads as a block rather than a paragraph.
Nesting follows parentheses. A derived table, or a subquery inside a WHERE clause, indents while it is open and returns to the outer level when it closes, which is usually enough to see the shape of a query somebody else wrote.
The three settings are keyword case (uppercase, lowercase or leave alone), comma placement (leading commas line up under the column list, trailing commas follow each column), and indent width at two or four spaces. Minify reverses all of it into one line for pasting into a string literal or a log query.
Limits Worth Knowing
- Square-bracket identifiers are not treated as protected text. A column written as [Date] or [Key] has its inner word matched against the keyword list and can be recased. That is cosmetic under a case-insensitive collation, but set Keywords to Preserve if you want the text untouched.
- Formatting overwrites the editor contents in place, with no undo step.
- There is no dialect switch and no validation. Invalid T-SQL is reformatted without complaint.
- Statement terminators split the output: each semicolon ends a line and the next statement starts after a blank line.
- Common table expressions are indented by their parentheses rather than given a dedicated layout, so a long WITH block reads less cleanly than a plain SELECT.
Common Questions
Does it understand stored procedure bodies?
Why did my bracketed column change case?
Can I undo a format?
More Format Tools
All formatters →Format an XML Document Online
Beautify and validate XML with chosen indentation. Free XML formatter that flags well-formedness errors by line, no signup.
Format JavaScript Online
Beautify and reindent messy or minified JavaScript with consistent formatting. Free online JavaScript formatter that runs in your browser.
Format & Beautify JSON Online
Paste minified or messy JSON and format it with proper indentation. Free online JSON formatter with validation.
Format SQL Queries Online
Beautify and indent SQL queries for better readability. Free online SQL formatter supporting MySQL, PostgreSQL, and more.
Format & Beautify XML Online
Paste XML data and format it with proper indentation and syntax highlighting. Free online XML formatter and validator.
Format & Beautify CSS Online
Paste minified or messy CSS and format it with proper indentation. Free online CSS formatter and beautifier.
Looking for FAQs and advanced options? Visit the full SQL Formatter page →