Skip to content
Back to skills

Stack Sqlserver

ASecurity

Microsoft SQL Server database — indexing, RCSI, set-based operations, SARGable queries, transaction scopes

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 6, 2026
ai-agentsgosqldatabaseperformance

Works with

  • cursor

Security analysis

A100/100

Scanned November 20, 2026

npx -y skills add Snakeblack/ospec-workflow --skill stack-sqlserver --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Stack Sqlserver?

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

Security grade badge for Stack Sqlserver
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/snakeblack-stack-sqlserver/badge)](https://www.skillsdirectory.com/skills/snakeblack-stack-sqlserver)

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: stack-sqlserver
description: "Microsoft SQL Server database — indexing, RCSI, set-based operations, SARGable queries, transaction scopes"
license: MIT AND Commons-Clause
metadata:
  author: manuel-retamozo-garcia
  version: "1.0"
capabilities: [sqlserver]
---

## Critical Rules

- **Index Design**: Clustered index keys should be sequential/monotonically increasing (e.g., identity columns, `NEWSEQUENTIALID()`) to minimize page splits. For non-clustered indexes, use the `INCLUDE` clause to cover queries instead of adding columns to the index key.
- **Concurrency (RCSI)**: Enable Read Committed Snapshot Isolation (RCSI) on the database level to prevent readers from blocking writers and writers from blocking readers.
- **Avoid Cursors**: Perform set-based operations rather than row-by-row operations (cursors, `WHILE` loops with index iteration) to optimize execution engine performance.
- **SARGable Queries**: Write Search Argumentable (SARGable) queries. Do not apply functions or calculations to indexed columns in the `WHERE` or `ON` clauses.
- **Transaction Scope**: Keep transactions as short and narrow as possible to minimize locking, page contention, and deadlocks.

## Indexing & Storage Best Practices

1. **Clustered Indexes**: Every table must have a clustered index. Prefer a narrow, static, sequential key. Avoid random GUIDs (`NEWID()`) as clustered keys as they cause heavy index fragmentation.
2. **Covering Indexes**: If a query selects specific columns, create a non-clustered index where the filter criteria columns form the index keys, and other selected columns are added using the `INCLUDE` clause:
   ```sql
   CREATE NONCLUSTERED INDEX IX_Orders_CustomerId_Status
   ON Orders (CustomerId, Status)
   INCLUDE (OrderDate, TotalAmount);
   ```

## Query Design & SARGability

1. **SARGable WHERE Clauses**:
   - **Bad**: `WHERE DATEADD(day, 7, OrderDate) >= GETDATE()` (Non-SARGable, index scan)
   - **Good**: `WHERE OrderDate >= DATEADD(day, -7, GETDATE())` (SARGable, index seek)
2. **Set-Based Operations**: Use joins, subqueries, and window functions (`ROW_NUMBER()`, `RANK()`) to manipulate datasets at once. Avoid iterating through table rows manually.

## Concurrency & RCSI

1. **RCSI Enablement**: Ensure RCSI is enabled:
   ```sql
   ALTER DATABASE YourDatabase SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE;
   ```
2. **Isolation Levels**: Rely on the default Read Committed isolation level (which uses row versioning under RCSI) instead of abusing dirty reads (`NOLOCK` table hints) or overly restrictive isolation levels (`SERIALIZABLE`).
3. **Short Transactions**: Execute non-database operations (HTTP requests, file I/O, slow calculations) outside of database transaction blocks.

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.