advanced-patterns

Provide advanced T-SQL patterns for SQL Server querying and data modification.

51|10|Updated Oct 22, 2025
One-click install
npx skills add https://github.com/JosiahSiegel/claude-plugin-marketplace --skill advanced-patterns-josiahsiegel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: advanced-patterns
Source: https://github.com/JosiahSiegel/claude-plugin-marketplace/tree/main/plugins/tsql-master/skills/advanced-patterns
Command: npx skills add https://github.com/JosiahSiegel/claude-plugin-marketplace --skill advanced-patterns-josiahsiegel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers and DBAs tackle complex T-SQL challenges in SQL Server, enabling more efficient and sophisticated data manipulation and querying.

Core Features & Use Cases

  • Advanced Querying: Utilize CTEs (including recursive), APPLY operators, and advanced grouping (ROLLUP, CUBE, GROUPING SETS) for intricate data retrieval.
  • Data Modification: Implement robust upsert logic with MERGE statements and capture row changes using the OUTPUT clause.
  • Temporal Data & Performance: Work with temporal tables for historical data tracking and leverage In-Memory OLTP for high-throughput scenarios.
  • Use Case: Optimize a reporting query that requires hierarchical data traversal and conditional aggregation by using recursive CTEs and GROUPING SETS.

Quick Start

Use the advanced-patterns skill to generate a recursive CTE example for hierarchical data.

Frequently Asked Questions about advanced-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a recursive CTE in T-SQL for hierarchical data traversal?

A recursive CTE in T-SQL traverses hierarchical data by repeatedly joining a base result set to itself. You define an anchor query for the root level, then add a recursive member that references the CTE to navigate child rows until all levels are resolved.

What is the best way to perform an upsert in SQL Server using the MERGE statement?

The MERGE statement performs an upsert in SQL Server by comparing a source table to a target table. It synchronizes the two by conditionally executing INSERT, UPDATE, or DELETE operations in a single atomic statement based on whether rows match.

How do APPLY operators work for complex querying in SQL Server?

APPLY operators in SQL Server evaluate a table-valued function or subquery for each row of an outer table. The CROSS APPLY returns only rows that produce results, while OUTER APPLY retains all outer rows even if the inner query yields nothing.

When do I need temporal tables for historical data tracking in T-SQL?

Temporal tables are needed when you require automatic historical data tracking in SQL Server. They maintain a history of all row changes over time, allowing you to query point-in-time data states without manually archiving previous versions.

Can I use In-Memory OLTP to improve high-throughput query performance in SQL Server?

In-Memory OLTP improves high-throughput query performance in SQL Server by storing tables entirely in memory. It eliminates disk I/O bottlenecks and uses native compilation to significantly reduce latency for heavy transactional workloads.

What are the differences between ROLLUP, CUBE, and GROUPING SETS for advanced grouping?

ROLLUP generates subtotal rows hierarchically, CUBE computes all possible subtotal combinations across grouping columns, and GROUPING SETS allows you to specify exact subtotal groupings. All three produce multiple levels of aggregated data in a single query.