code-analysis
Installation
SKILL.md
T-SQL Code Analysis
Use this skill when the user asks to refactor, fix, explain, document, or analyze a T-SQL script.
Scope
- Reviews code without executing it: correctness, performance anti-patterns (non-SARGable predicates, implicit conversions, cursors,
SELECT *, row-by-row DML), SQL injection in dynamic SQL, refactoring, and documentation. - For a cost-validated rewrite of one query, use
query-rewrite; for execution plan analysis, useplan-analysis.
Required tools
- A SQL query tool connected to the target server and database. Prefer, in order: the SQL Tools MCP server that ships with the
microsoft-sql-adminplugin (mssql_list_database_connections,mssql_connect_database, thenmssql_execute_query); any other SQL tool the agent host provides for running T-SQL and reading result sets;sqlcmdfrom a terminal. It is used read-only (syntax validation and schema inspection), and to execute a schema change only when the user asks you to make it. If the SQL Tools MCP server is not connected or lists no connections, follow thesql-tools-mcp-setupskill, which asks before installing or configuring anything. If no SQL tool can be made available, give the user the T-SQL to run and ask for the results.
Validating Syntax
Validate a script in the database context without executing it. If the active tool catalog has mssql_validate_syntax, use it: it compiles every batch of a GO script in order on one connection, executes nothing, and reports a batch that needs an object an earlier batch creates as unverifiable. Otherwise send the SET statements and the script in one request, each SET in its own batch: