Skip to content
Back to skills

Sql Expert

ASecurity

Write, optimize, and debug T-SQL queries for Microsoft SQL Server. Covers CTEs, window functions, PIVOT, MERGE, APPLY operators, execution plan analysis, indexing strategies, and stored procedures. Use when working with SQL Server, T-SQL scripts, .sql files, stored procedures, query optimization, or database performance tuning.

  • 416 stars
  • 0 votes
  • 1 copy
  • 13 views
  • Added February 7, 2026
databasesgosqldatabasesecurityperformance

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned February 10, 2026

npx -y skills add aiskillstore/marketplace --skill sql-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sql Expert?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sql Expert
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/aiskillstore-sql-expert/badge)](https://www.skillsdirectory.com/skills/aiskillstore-sql-expert)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sql-expert
description: Write, optimize, and debug T-SQL queries for Microsoft SQL Server. Covers CTEs, window functions, PIVOT, MERGE, APPLY operators, execution plan analysis, indexing strategies, and stored procedures. Use when working with SQL Server, T-SQL scripts, .sql files, stored procedures, query optimization, or database performance tuning.
---

# SQL Expert

Expert assistance for Microsoft SQL Server and T-SQL development.

## Instructions

When helping with T-SQL:

1. **Gather context first** - Ask about table structures, relationships, data volumes, and SQL Server version if not provided
2. **Write for performance** - Produce queries that scale, avoiding anti-patterns from the start
3. **Explain reasoning** - Describe why a technique was chosen, not just how it works
4. **Present alternatives** - When multiple approaches exist, explain trade-offs
5. **Handle edge cases** - Consider NULLs, empty result sets, and boundary conditions
6. **Note version requirements** - Flag features that require specific SQL Server versions

## Core Capabilities

- **Query optimization**: Execution plan analysis, index recommendations, eliminating anti-patterns
- **Advanced techniques**: CTEs (recursive/non-recursive), window functions, PIVOT/UNPIVOT, MERGE, CROSS/OUTER APPLY
- **Data processing**: JSON/XML handling, temporal tables, dynamic SQL
- **Stored procedures**: Error handling with TRY...CATCH, transaction management, table-valued parameters

## Quick Reference

### Anti-Patterns to Catch

```sql
-- Non-SARGable (BAD)
WHERE YEAR(date_column) = 2024
-- SARGable (GOOD)
WHERE date_column >= '2024-01-01' AND date_column < '2025-01-01'

-- Implicit conversion (BAD)
WHERE nvarchar_column = @varchar_param
-- Type match (GOOD)
WHERE nvarchar_column = @nvarchar_param
```

### Error Handling Template

```sql
BEGIN TRY
    BEGIN TRANSACTION;
    -- operations
    COMMIT TRANSACTION;
END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
    THROW;
END CATCH;
```

### Version-Specific Features

| Feature | Version |
|---------|---------|
| STRING_AGG, TRIM | 2017+ |
| JSON functions, STRING_SPLIT | 2016+ |
| GENERATE_SERIES, GREATEST/LEAST | 2022+ |

## Additional References

- [references/patterns.md](references/patterns.md) - Query patterns and templates (CTEs, pagination, PIVOT, MERGE, window functions)
- [references/performance.md](references/performance.md) - Execution plan analysis, parameter sniffing, Query Store, wait statistics
- [references/security.md](references/security.md) - SQL injection prevention, dynamic SQL safety, permissions, data masking
- [references/data-types.md](references/data-types.md) - Type selection, collation handling, precision/scale, storage optimization
- [references/transactions.md](references/transactions.md) - Isolation levels, deadlock prevention, distributed transactions, sagas

Files in this skill

  • SKILL.md2.8 KB
  • evaluation.json11.1 KB
  • references/data-types.md11.1 KB
  • references/patterns.md4 KB
  • references/performance.md8.9 KB
  • references/security.md9.5 KB
  • references/transactions.md13.5 KB
  • skill-report.json29.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…