AgentSkillsCN

sql-server

运用 T-SQL、存储过程、索引与性能优化技术,开发 SQL Server 数据库。在编写 T-SQL 查询、创建存储过程/函数、设计索引策略、优化查询执行计划,或排查 SQL Server 性能问题时,可使用此技能。

SKILL.md
--- frontmatter
name: "sql-server"
description: 'Develop SQL Server databases with T-SQL, stored procedures, indexing, and performance optimization. Use when writing T-SQL queries, creating stored procedures/functions, designing index strategies, optimizing query execution plans, or troubleshooting SQL Server performance.'
metadata:
  author: "AgentX"
  version: "1.0.0"
  created: "2025-01-15"
  updated: "2025-01-15"
compatibility:
  languages: ["sql", "tsql"]
  platforms: ["windows", "linux"]

SQL Server Database Development

Purpose: Production-ready SQL Server development for enterprise applications.
Audience: Backend engineers and database administrators working with Microsoft SQL Server.
Standard: Follows github/awesome-copilot SQL Server patterns.


When to Use This Skill

  • Writing T-SQL queries and stored procedures
  • Designing SQL Server index strategies
  • Optimizing query execution plans
  • Using window functions and CTEs
  • Troubleshooting SQL Server performance issues

Prerequisites

  • SQL Server 2019+ or Azure SQL Database
  • SSMS, Azure Data Studio, or DBeaver client

Quick Reference

NeedSolutionPattern
Stored procedureCREATE PROCEDURECREATE PROCEDURE GetUser @UserId INT AS BEGIN ... END
TransactionBEGIN/COMMIT/ROLLBACKBEGIN TRANSACTION; ... COMMIT;
Error handlingTRY...CATCHBEGIN TRY ... END TRY BEGIN CATCH ... END CATCH
IndexingCREATE INDEXCREATE NONCLUSTERED INDEX ON Users(Email)
Query optimizationExecution planSET STATISTICS IO ON; SET STATISTICS TIME ON;
UpsertMERGE statementMERGE INTO target USING source ON ...

SQL Server Version

Current: SQL Server 2022
Minimum: SQL Server 2019


Common Pitfalls

IssueProblemSolution
**SELECT ***Unnecessary data transferSelect only needed columns
Missing indexesTable scansAdd indexes on WHERE/JOIN columns
Functions on columnsPrevents index usageRewrite without functions
Implicit conversionsPerformance hitMatch data types
CURSOR usageSlow row-by-row processingUse set-based operations
No error handlingSilent failuresUse TRY...CATCH blocks

Resources


See Also: Skills.mdAGENTS.mdDatabase Skill

Last Updated: January 27, 2026

Troubleshooting

IssueSolution
Query timeoutCheck execution plan for table scans, add missing indexes, update statistics
Deadlock victim errorsAccess tables in consistent order, keep transactions short, use NOLOCK for read-only queries
Stored procedure parameter sniffingUse OPTION (RECOMPILE) or local variables for parameter values

References