A VS Code extension that formats T-SQL statements consistently.
Install
Install Clean T-SQL Formatter from the Visual Studio Code Extensions view:
- Open Extensions in VS Code.
- Search for "Clean T-SQL Formatter" or
clean-tsql-formatter.
- Select the extension and choose Install.
Alternatively, build and install a VSIX locally or run the extension in the Extension Development Host (see Build & Run Locally).
Build & Run Locally
- Clone the repository:
git clone https://github.com/JMatos1221/tsql-formatter.git
cd tsql-formatter
- Install dependencies and compile:
npm install
npm run compile
- Open the project in VS Code and press F5 to launch the Extension Development Host.
Use
Open a .sql file and run Format Document (right-click → Format Document, Command Palette → Format Document, or use your keybinding). To format automatically on save, enable Editor: Format On Save.
Settings
tsqlFormatter.linesBetweenQueries (number, default: 2): Number of empty lines between top-level statements.
tsqlFormatter.breakOnKeywords (boolean, default: true): Place keywords like WHERE, JOIN, AND, OR on their own lines.
tsqlFormatter.keywordCase (upper | lower | preserve, default: preserve): Keyword casing mode.
tsqlFormatter.elementCase (upper | lower | preserve | matchTable, default: preserve): Identifier casing for tables/columns.
tsqlFormatter.useBrackets (boolean, default: false): Wrap identifiers in square brackets (e.g., [TableName]).
Change these in VS Code Settings by searching for tsqlFormatter.
Example
Before:
select id, name from users where active=1 order by name
After (with defaults and keywordCase: "upper"):
SELECT id, name
FROM users
WHERE active = 1
ORDER BY name
Notes
License: MIT